code
stringlengths
73
34.1k
label
stringclasses
1 value
private void buildSectionHeaders(){ // Update Artist maps HashMap<String, List<com.ftinc.kit.attributr.model.Library>> currMap = new HashMap<>(); // Loop through tuneRefs for(int i=0; i<getItemCount(); i++){ com.ftinc.kit.attributr.model.Library library = getItem(i); ...
java
public void setChangeLog(ChangeLog log){ mChangeLog = log; // Clear out any existing entries clear(); //sort all the changes Collections.sort(mChangeLog.versions, new VersionComparator()); // Iterate and add all the 'Change' objects in the adapter for(Version v...
java
@SuppressLint("NewApi") @Override public void onItemClick(View v, com.ftinc.kit.attributr.model.Library item, int position) { if(BuildUtils.isLollipop()){ v.setElevation(SizeUtils.dpToPx(this, 4)); } View name = ButterKnife.findById(v, R.id.line_1); View author = But...
java
private void parseExtras(Bundle icicle){ Intent intent = getIntent(); if(intent != null){ mXmlConfigId = intent.getIntExtra(EXTRA_CONFIG, -1); mTitle = intent.getStringExtra(EXTRA_TITLE); } if(icicle != null){ mXmlConfigId = icicle.getInt(EXTRA_CONFI...
java
public static boolean checkForRunningService(Context ctx, String serviceClassName) { ActivityManager manager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (serviceClass...
java
public static Intent openPlayStore(Context context, boolean openInBrowser) { String appPackageName = context.getPackageName(); Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)); if (isIntentAvailable(context, marketIntent)) { ret...
java
public static Intent sendEmail(String to, String subject, String text) { return sendEmail(new String[]{to}, subject, text); }
java
public static Intent shareText(String subject, String text) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); if (!TextUtils.isEmpty(subject)) { intent.putExtra(Intent.EXTRA_SUBJECT, subject); } intent.putExtra(Intent.EXTRA_TEXT, text); int...
java
public static Intent showLocation(float latitude, float longitude, Integer zoomLevel) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); String data = String.format("geo:%s,%s", latitude, longitude); if (zoomLevel != null) { data = String.format("%s?z=%s", ...
java
public static Intent findLocation(String query) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); String data = String.format("geo:0,0?q=%s", query); intent.setData(Uri.parse(data)); return intent; }
java
public static Intent openLink(String url) { // if protocol isn't defined use http by default if (!TextUtils.isEmpty(url) && !url.contains("://")) { url = "http://" + url; } Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri...
java
public static Intent pickImage() { Intent intent = new Intent(Intent.ACTION_PICK); intent.setType("image/*"); return intent; }
java
public static boolean isCropAvailable(Context context) { Intent intent = new Intent("com.android.camera.action.CROP"); intent.setType("image/*"); return IntentUtils.isIntentAvailable(context, intent); }
java
public static Intent photoCapture(String file) { Uri uri = Uri.fromFile(new File(file)); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); return intent; }
java
public static boolean isIntentAvailable(Context context, Intent intent) { PackageManager packageManager = context.getPackageManager(); List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; }
java
public static float spToPx(Context ctx, float spSize){ return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spSize, ctx.getResources().getDisplayMetrics()); }
java
public void setForegroundGravity(int foregroundGravity) { if (mForegroundGravity != foregroundGravity) { if ((foregroundGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) { foregroundGravity |= Gravity.START; } if ((foregroundGravity & Gravity.VERTICAL...
java
public void setForeground(Drawable drawable) { if (mForeground != drawable) { if (mForeground != null) { mForeground.setCallback(null); unscheduleDrawable(mForeground); } mForeground = drawable; if (drawable != null) { ...
java
public static int crapToDisk(Context ctx, String filename, byte[] data){ int code = IO_FAIL; File dir = Environment.getExternalStorageDirectory(); File output = new File(dir, filename); try { FileOutputStream fos = new FileOutputStream(output); try { ...
java
public static Bitmap getVideoThumbnail(String videoPath){ MediaMetadataRetriever mmr = new MediaMetadataRetriever(); mmr.setDataSource(videoPath); return mmr.getFrameAtTime(); }
java
public static void getVideoThumbnail(String videoPath, final VideoThumbnailCallback cb){ new AsyncTask<String, Void, Bitmap>(){ @Override protected Bitmap doInBackground(String... params) { if(params.length > 0) { String path = params[0]; ...
java
public static boolean copy(File source, File output){ // Check to see if output exists if(output.exists() && output.canWrite()){ // Delete the existing file, and create a new one if(output.delete()) { try { output.createNewFile(); ...
java
public static String fancyTimestamp(long epoch){ // First, check to see if it's within 1 minute of the current date if(System.currentTimeMillis() - epoch < 60000){ return "Just now"; } // Get calendar for just now Calendar now = Calendar.getInstance(); // G...
java
public static String formatHumanFriendlyShortDate(final Context context, long timestamp) { long localTimestamp, localTime; long now = System.currentTimeMillis(); TimeZone tz = TimeZone.getDefault(); localTimestamp = timestamp + tz.getOffset(timestamp); localTime = now + tz.getOf...
java
public static boolean isColorDark(int color) { return ((30 * Color.red(color) + 59 * Color.green(color) + 11 * Color.blue(color)) / 100) <= BRIGHTNESS_THRESHOLD; }
java
@Override public View getView(int position, View convertView, ViewGroup parent){ VH holder; if(convertView == null){ // Load the view from scratch convertView = inflater.inflate(viewResource, parent, false); // Load the ViewHolder holder = createHolder(convertView); // set holder t...
java
private static boolean validateVersion(Context ctx, ChangeLog clog){ // Get Preferences SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); int lastSeen = prefs.getInt(PREF_CHANGELOG_LAST_SEEN, -1); // Second sort versions by it's code int latest = Int...
java
public void enableWatcher(TextWatcher watcher, boolean enabled){ int index = mWatchers.indexOfValue(watcher); if(index >= 0){ int key = mWatchers.keyAt(index); mEnabledKeys.put(key, enabled); } }
java
private void parseAttributes(Context context, AttributeSet attrs, int defStyle){ int defaultColor = context.getResources().getColor(R.color.black26); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.EmptyView, defStyle, 0); if (a == null) { mEmpt...
java
public void setIcon(Drawable drawable){ mIcon.setImageDrawable(drawable); mIcon.setVisibility(View.VISIBLE); }
java
public void setIconSize(int size){ mEmptyIconSize = size; int width = mEmptyIconSize == -1 ? WRAP_CONTENT : mEmptyIconSize; int height = mEmptyIconSize == -1 ? WRAP_CONTENT : mEmptyIconSize; LinearLayout.LayoutParams iconParams = new LinearLayout.LayoutParams(width, height); mIco...
java
public void setActionLabel(CharSequence label){ mEmptyActionText = label; mAction.setText(mEmptyActionText); mAction.setVisibility(TextUtils.isEmpty(mEmptyActionText) ? View.GONE : View.VISIBLE); }
java
@Deprecated public void setLoading(){ mState = STATE_LOADING; mProgress.setVisibility(View.VISIBLE); mAction.setVisibility(View.GONE); mMessage.setVisibility(View.GONE); mIcon.setVisibility(View.GONE); }
java
@Deprecated public void setEmpty(){ mState = STATE_EMPTY; mProgress.setVisibility(View.GONE); if(mEmptyIcon != -1) mIcon.setVisibility(View.VISIBLE); if(!TextUtils.isEmpty(mEmptyMessage)) mMessage.setVisibility(View.VISIBLE); if(!TextUtils.isEmpty(mEmptyActionText)) mAction.s...
java
private View getNextView(RecyclerView parent) { View firstView = parent.getChildAt(0); // draw the first visible child's header at the top of the view int firstPosition = parent.getChildPosition(firstView); View firstHeader = getHeaderView(parent, firstPosition); for (int i = 0...
java
@SuppressLint("NewApi") private void buildAndAttach(){ // Disable any pending transition on the activity since we are transforming it mActivity.overridePendingTransition(0, 0); // Setup window flags if Lollipop if(BuildUtils.isLollipop()) { Window window = mActivity.getW...
java
private void setupDrawer(){ // Setup drawer background color if set int backgroundColor = UIUtils.getColorAttr(mActivity, R.attr.drawerBackground); if(backgroundColor > 0){ mDrawerPane.setBackgroundColor(backgroundColor); } // Set the drawer layout statusbar color ...
java
private void createNavDrawerItems(){ if (mDrawerItemsListContainer == null) { return; } mNavDrawerItemViews.clear(); mDrawerItemsListContainer.removeAllViews(); for (DrawerItem item: mDrawerItems) { item.setSelected(item.getId() == mSelectedItem); ...
java
private void onNavDrawerItemClicked(final int itemId) { if (itemId == mSelectedItem) { mDrawerLayout.closeDrawer(GravityCompat.START); return; } if (isSpecialItem(itemId)) { goToNavDrawerItem(itemId); } else { // launch the target Activity...
java
private void formatNavDrawerItem(DrawerItem item, boolean selected) { if (item instanceof SeperatorDrawerItem || item instanceof SwitchDrawerItem) { // not applicable return; } // Get the associated view View view = mNavDrawerItemViews.get(item.getId()); ...
java
private DrawerLayout inflateDrawerLayout(ViewGroup parent){ DrawerLayout drawer = (DrawerLayout) mActivity.getLayoutInflater() .inflate(R.layout.material_drawer, parent, false); // Find the associated views mDrawerPane = ButterKnife.findById(drawer, R.id.navdrawer); mDra...
java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { Drawable drawable = getDrawable(); if (getDrawable() != null) { if (ratioType == RATIO_WIDTH) { int width = MeasureSpec.getSize(widthMeasureSpec); int height = Math.round(width * (((float) drawable.getIntrinsicHeight()) / ...
java
public static int getStatusBarHeight(Context ctx) { int result = 0; int resourceId = ctx.getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { result = ctx.getResources().getDimensionPixelSize(resourceId); } return result; }
java
protected void onItemClick(View view, int position){ if(itemClickListener != null) itemClickListener.onItemClick(view, getItem(position), position); }
java
protected void onItemLongClick(View view, int position){ if(itemLongClickListener != null) itemLongClickListener.onItemLongClick(view, getItem(position), position); }
java
public void setEmptyView(View emptyView){ if(this.emptyView != null){ unregisterAdapterDataObserver(mEmptyObserver); } this.emptyView = emptyView; registerAdapterDataObserver(mEmptyObserver); }
java
private void checkIfEmpty(){ if(emptyView != null){ emptyView.setVisibility(getItemCount() > 0 ? View.GONE : View.VISIBLE); } }
java
public void addAll(Collection<? extends M> collection) { if (collection != null) { items.addAll(collection); applyFilter(); } }
java
public M remove(int index){ M item = items.remove(index); applyFilter(); return item; }
java
public void moveItem(int start, int end){ M startItem = filteredItems.get(start); M endItem = filteredItems.get(end); int realStart = items.indexOf(startItem); int realEnd = items.indexOf(endItem); Collections.swap(items, realStart, realEnd); applyFilter(); onI...
java
private void applyFilter(){ filteredItems.clear(); Filter<M> filter = getFilter(); if(filter == null){ filteredItems.addAll(items); }else{ for (int i = 0; i < items.size(); i++) { M item = items.get(i); if(filter.filter(item, query...
java
@Override public void onBindViewHolder(final VH vh, final int i) { if(itemClickListener != null){ vh.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int position = vh.getAdapterPosition(); ...
java
@Override public long getItemId(int position) { if(position > RecyclerView.NO_ID && position < getItemCount()) { M item = getItem(position); if (item != null) return item.hashCode(); return position; } return RecyclerView.NO_ID; }
java
public static Intent createIntent(Context ctx, int logoResId, CharSequence eulaText){ Intent intent = new Intent(ctx, EulaActivity.class); intent.putExtra(EXTRA_LOGO, logoResId); intent.putExtra(EXTRA_EULA_TEXT, eulaText); return intent; }
java
public String getLicenseText(){ if(license != null){ return license.getLicense(description, year, author, email); } return "N/A"; }
java
public static Intent getCameraCaptureIntent(Context ctx, String authority){ Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); try { // Get the app's local file storage mCurrentCaptureUri = createAccessibleTempFile(ctx, authority); grantPermissions(ctx, mCur...
java
public static Intent getChooseMediaIntent(String mimeType){ Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType(mimeType); return intent; }
java
public static Observable<File> handleActivityResult(final Context context, int resultCode, int requestCode, Intent data){ if(resultCode == Activity.RESULT_OK){ switch (requestCode){ case CAPTURE_PHOTO_REQUEST_CODE: if(mCurrentCaptureUri != null){ ...
java
private static Uri createAccessibleTempFile(Context ctx, String authority) throws IOException { File dir = new File(ctx.getCacheDir(), "camera"); File tmp = createTempFile(dir); // Give permissions return FileProvider.getUriForFile(ctx, authority, tmp); }
java
private static void grantPermissions(Context ctx, Uri uri){ Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); List<ResolveInfo> resolvedIntentActivities = ctx.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolvedIntentInfo : re...
java
private static void revokePermissions(Context ctx, Uri uri){ ctx.revokeUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); }
java
public static String cleanFilename(String fileName){ int lastIndex = fileName.lastIndexOf("."); return fileName.substring(0, lastIndex); }
java
public static boolean isEmulator(){ return "google_sdk".equals(Build.PRODUCT) || Build.PRODUCT.contains("sdk_google_phone") || "sdk".equals(Build.PRODUCT) || "sdk_x86".equals(Build.PRODUCT) || "vbox86p".equals(Build.PRODUCT); }
java
public static int getGMTOffset(){ Calendar now = Calendar.getInstance(); return (now.get(Calendar.ZONE_OFFSET) + now.get(Calendar.DST_OFFSET)) / 3600000; }
java
public static String getMimeType(String url) { String type = null; String extension = MimeTypeMap.getFileExtensionFromUrl(url); if (extension != null) { MimeTypeMap mime = MimeTypeMap.getSingleton(); type = mime.getMimeTypeFromExtension(extension); } return type; }
java
public static float distance(PointF p1, PointF p2){ return (float) Math.sqrt(Math.pow((p2.x - p1.x), 2) + Math.pow(p2.y - p1.y,2)); }
java
public static float parseFloat(String val, float defVal){ if(TextUtils.isEmpty(val)) return defVal; try{ return Float.parseFloat(val); }catch (NumberFormatException e){ return defVal; } }
java
public static int parseInt(String val, int defValue){ if(TextUtils.isEmpty(val)) return defValue; try{ return Integer.parseInt(val); }catch (NumberFormatException e){ return defValue; } }
java
public static long parseLong(String val, long defValue){ if(TextUtils.isEmpty(val)) return defValue; try{ return Long.parseLong(val); }catch (NumberFormatException e){ return defValue; } }
java
public static double parseDouble(String val, double defValue){ if(TextUtils.isEmpty(val)) return defValue; try{ return Double.parseDouble(val); }catch(NumberFormatException e){ return defValue; } }
java
private void configAppBar(){ setSupportActionBar(mAppbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle(R.string.changelog_activity_title); mAppbar.setNavigationOnClickListener(this); }
java
public static void apply(TextView textView, Face type){ // First check for existing typefaces Typeface typeface = getTypeface(textView.getContext(), type); if (typeface != null) textView.setTypeface(typeface); }
java
public static void apply(Face type, TextView... textViews){ if(textViews.length == 0) return; for (int i = 0; i < textViews.length; i++) { apply(textViews[i], type); } }
java
public static Typeface getTypeface(Context ctx, Face type){ return getTypeface(ctx, "fonts/" + type.getFontFileName()); }
java
public void start() { eb = vertx.eventBus(); config = config(); FileResolver.getInstance().setBasePath(config); }
java
public Plan makeSelectPlan() { Plan p = makeIndexSelectPlan(); if (p == null) p = tp; return addSelectPredicate(p); }
java
public Plan makeJoinPlan(Plan trunk) { Schema trunkSch = trunk.schema(); Predicate joinPred = pred.joinPredicate(sch, trunkSch); if (joinPred == null) return null; Plan p = makeIndexJoinPlan(trunk, trunkSch); if (p == null) p = makeProductJoinPlan(trunk, trunkSch); return p; }
java
public Plan makeProductPlan(Plan trunk) { Plan p = makeSelectPlan(); return new MultiBufferProductPlan(trunk, p, tx); }
java
public AccountService getAccountService() { if (_accountService == null) { synchronized (CCApi2.class) { if (_accountService == null) { _accountService = _retrofit.create(AccountService.class); } } } return _accountServ...
java
public CampaignService getCampaignService() { if (_campaignService == null) { synchronized (CCApi2.class) { if (_campaignService == null) { _campaignService = _retrofit.create(CampaignService.class); } } } return _campa...
java
public ContactService getContactService() { if (_contactService == null) { synchronized (CCApi2.class) { if (_contactService == null) { _contactService = _retrofit.create(ContactService.class); } } } return _contactServ...
java
public LibraryService getLibraryService() { if (_libraryService == null) { synchronized (CCApi2.class) { if (_libraryService == null) { _libraryService = _retrofit.create(LibraryService.class); } } } return _libraryServ...
java
public CampaignTrackingService getCampaignTrackingService() { if (_campaignTrackingService == null) { synchronized (CCApi2.class) { if (_campaignTrackingService == null) { _campaignTrackingService = _retrofit.create(CampaignTrackingService.class); ...
java
public ContactTrackingService getContactTrackingService() { if (_contactTrackingService == null) { synchronized (CCApi2.class) { if (_contactTrackingService == null) { _contactTrackingService = _retrofit.create(ContactTrackingService.class); } ...
java
public BulkActivitiesService getBulkActivitiesService() { if (_bulkActivitiesService == null) { synchronized (CCApi2.class) { if (_bulkActivitiesService == null) { _bulkActivitiesService = _retrofit.create(BulkActivitiesService.class); } ...
java
public void createTable(String tblName, Schema sch, Transaction tx) { if (tblName != TCAT_TBLNAME && tblName != FCAT_TBLNAME) formatFileHeader(tblName, tx); // Optimization: store the ti tiMap.put(tblName, new TableInfo(tblName, sch)); // insert one record into tblcat RecordFile tcatfile = tcatInfo...
java
public void dropTable(String tblName, Transaction tx) { // Remove the file RecordFile rf = getTableInfo(tblName, tx).open(tx, true); rf.remove(); // Optimization: remove from the TableInfo map tiMap.remove(tblName); // remove the record from tblcat RecordFile tcatfile = tcatInfo.open(tx, true);...
java
public TableInfo getTableInfo(String tblName, Transaction tx) { // Optimization: TableInfo resultTi = tiMap.get(tblName); if (resultTi != null) return resultTi; RecordFile tcatfile = tcatInfo.open(tx, true); tcatfile.beforeFirst(); boolean found = false; while (tcatfile.next()) { String t...
java
public static void startUp(int port) throws Exception { // create a registry specific for the server on the default port Registry reg = LocateRegistry.createRegistry(port); // and post the server entry in it RemoteDriver d = new RemoteDriverImpl(); reg.rebind("vanilladb-sp", d); }
java
@Override public Scan open() { Scan src = p.open(); List<TempTable> runs = splitIntoRuns(src); /* * If the input source scan has no record, the temp table list will * result in size 0. Need to check the size of "runs" here. */ if (runs.size() == 0) return src; src.close(); while (run...
java
@Override public boolean next() { if (isLhsEmpty) return false; if (s2.next()) return true; else if (!(isLhsEmpty = !s1.next())) { s2.beforeFirst(); return s2.next(); } else { return false; } }
java
void sLock(Object obj, long txNum) { Object anchor = getAnchor(obj); txWaitMap.put(txNum, anchor); synchronized (anchor) { Lockers lks = prepareLockers(obj); if (hasSLock(lks, txNum)) return; try { long timestamp = System.currentTimeMillis(); while (!sLockable(lks, txNum) && !wai...
java
void xLock(Object obj, long txNum) { Object anchor = getAnchor(obj); txWaitMap.put(txNum, anchor); synchronized (anchor) { Lockers lks = prepareLockers(obj); if (hasXLock(lks, txNum)) return; try { long timestamp = System.currentTimeMillis(); while (!xLockable(lks, txNum) && !wai...
java
void sixLock(Object obj, long txNum) { Object anchor = getAnchor(obj); txWaitMap.put(txNum, anchor); synchronized (anchor) { Lockers lks = prepareLockers(obj); if (hasSixLock(lks, txNum)) return; try { long timestamp = System.currentTimeMillis(); while (!sixLockable(lks, txNum) &...
java
void isLock(Object obj, long txNum) { Object anchor = getAnchor(obj); txWaitMap.put(txNum, anchor); synchronized (anchor) { Lockers lks = prepareLockers(obj); if (hasIsLock(lks, txNum)) return; try { long timestamp = System.currentTimeMillis(); while (!isLockable(lks, txNum) && !wait...
java
void ixLock(Object obj, long txNum) { Object anchor = getAnchor(obj); txWaitMap.put(txNum, anchor); synchronized (anchor) { Lockers lks = prepareLockers(obj); if (hasIxLock(lks, txNum)) return; try { long timestamp = System.currentTimeMillis(); while (!ixLockable(lks, txNum) && !...
java
void release(Object obj, long txNum, int lockType) { Object anchor = getAnchor(obj); synchronized (anchor) { Lockers lks = lockerMap.get(obj); /* * In some situation, tx will release the lock of the object that * have been released. */ if (lks != null) { releaseLock(lks, anchor, tx...
java
void releaseAll(long txNum, boolean sLockOnly) { Set<Object> objectsToRelease = getObjectSet(txNum); for (Object obj : objectsToRelease) { Object anchor = getAnchor(obj); synchronized (anchor) { Lockers lks = lockerMap.get(obj); if (lks != null) { if (hasSLock(lks, txNum)) relea...
java
public void close() { if (blk != null) { tx.bufferMgr().unpin(currentBuff); blk = null; currentBuff = null; } }
java
public boolean hasDataRecords() { long blkNum = (Long) getVal(OFFSET_TS_BLOCKID, BIGINT).asJavaVal(); return blkNum != NO_SLOT_BLOCKID ? true : false; }
java