idx int64 0 165k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
19,300 | private void buildSectionHeaders ( ) { HashMap < String , List < com . ftinc . kit . attributr . model . Library > > currMap = new HashMap < > ( ) ; for ( int i = 0 ; i < getItemCount ( ) ; i ++ ) { com . ftinc . kit . attributr . model . Library library = getItem ( i ) ; String license = library . license . formalName ( ) ; List < com . ftinc . kit . attributr . model . Library > libraries = currMap . get ( license ) ; if ( libraries != null ) { libraries . add ( library ) ; currMap . put ( license , libraries ) ; } else { libraries = new ArrayList < > ( ) ; libraries . add ( library ) ; currMap . put ( license , libraries ) ; } } mHeaders . clear ( ) ; mHeaders . addAll ( currMap . values ( ) ) ; mTitles . clear ( ) ; mTitles . addAll ( currMap . keySet ( ) ) ; } | Build the section headers for use in creating the headers |
19,301 | public void setChangeLog ( ChangeLog log ) { mChangeLog = log ; clear ( ) ; Collections . sort ( mChangeLog . versions , new VersionComparator ( ) ) ; for ( Version version : mChangeLog . versions ) { addAll ( version . changes ) ; } notifyDataSetChanged ( ) ; } | Set the changelog for this adapter |
19,302 | @ SuppressLint ( "NewApi" ) 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 = ButterKnife . findById ( v , R . id . line_2 ) ; Pair < View , String > [ ] transitions = new Pair [ ] { new Pair < > ( v , "display_content" ) , new Pair < > ( name , "library_name" ) , new Pair < > ( author , "library_author" ) , new Pair < > ( mToolbar , "app_bar" ) } ; Intent details = new Intent ( this , com . ftinc . kit . attributr . ui . DetailActivity . class ) ; details . putExtra ( com . ftinc . kit . attributr . ui . DetailActivity . EXTRA_LIBRARY , item ) ; startActivity ( details ) ; } | Called when a Library item is clicked . |
19,303 | 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_CONFIG , - 1 ) ; mTitle = icicle . getString ( EXTRA_TITLE ) ; } if ( mXmlConfigId == - 1 ) finish ( ) ; if ( ! TextUtils . isEmpty ( mTitle ) ) getSupportActionBar ( ) . setTitle ( mTitle ) ; List < com . ftinc . kit . attributr . model . Library > libs = com . ftinc . kit . attributr . internal . Parser . parse ( this , mXmlConfigId ) ; mAdapter = new com . ftinc . kit . attributr . ui . LibraryAdapter ( ) ; mAdapter . addAll ( libs ) ; mAdapter . sort ( new com . ftinc . kit . attributr . model . Library . LibraryComparator ( ) ) ; mAdapter . notifyDataSetChanged ( ) ; } | Parse the Intent or saved bundle extras for the configuration and title data |
19,304 | 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 ( serviceClassName . equals ( service . service . getClassName ( ) ) ) { return true ; } } return false ; } | Check for a running service |
19,305 | 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 ) ) { return marketIntent ; } if ( openInBrowser ) { return openLink ( "https://play.google.com/store/apps/details?id=" + appPackageName ) ; } return marketIntent ; } | Open app page at Google Play |
19,306 | public static Intent sendEmail ( String to , String subject , String text ) { return sendEmail ( new String [ ] { to } , subject , text ) ; } | Send email message |
19,307 | 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 ) ; intent . setType ( "text/plain" ) ; return intent ; } | Share text via thirdparty app like twitter facebook email sms etc . |
19,308 | 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" , data , zoomLevel ) ; } intent . setData ( Uri . parse ( data ) ) ; return intent ; } | Opens the Maps application to the given location . |
19,309 | 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 ; } | Opens the Maps application to the given query . |
19,310 | public static Intent openLink ( String url ) { if ( ! TextUtils . isEmpty ( url ) && ! url . contains ( "://" ) ) { url = "http://" + url ; } Intent intent = new Intent ( ) ; intent . setAction ( Intent . ACTION_VIEW ) ; intent . setData ( Uri . parse ( url ) ) ; return intent ; } | Open a browser window to the URL specified . |
19,311 | public static Intent pickImage ( ) { Intent intent = new Intent ( Intent . ACTION_PICK ) ; intent . setType ( "image/*" ) ; return intent ; } | Pick image from gallery |
19,312 | public static boolean isCropAvailable ( Context context ) { Intent intent = new Intent ( "com.android.camera.action.CROP" ) ; intent . setType ( "image/*" ) ; return IntentUtils . isIntentAvailable ( context , intent ) ; } | Check that cropping application is available |
19,313 | 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 ; } | Call standard camera application for capturing an image |
19,314 | 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 ; } | Check that in the system exists application which can handle this intent |
19,315 | public static float spToPx ( Context ctx , float spSize ) { return TypedValue . applyDimension ( TypedValue . COMPLEX_UNIT_SP , spSize , ctx . getResources ( ) . getDisplayMetrics ( ) ) ; } | Convert Scale - Dependent Pixels to actual pixels |
19,316 | public void setForegroundGravity ( int foregroundGravity ) { if ( mForegroundGravity != foregroundGravity ) { if ( ( foregroundGravity & Gravity . RELATIVE_HORIZONTAL_GRAVITY_MASK ) == 0 ) { foregroundGravity |= Gravity . START ; } if ( ( foregroundGravity & Gravity . VERTICAL_GRAVITY_MASK ) == 0 ) { foregroundGravity |= Gravity . TOP ; } mForegroundGravity = foregroundGravity ; if ( mForegroundGravity == Gravity . FILL && mForeground != null ) { Rect padding = new Rect ( ) ; mForeground . getPadding ( padding ) ; } requestLayout ( ) ; } } | Describes how the foreground is positioned . Defaults to START and TOP . |
19,317 | public void setForeground ( Drawable drawable ) { if ( mForeground != drawable ) { if ( mForeground != null ) { mForeground . setCallback ( null ) ; unscheduleDrawable ( mForeground ) ; } mForeground = drawable ; if ( drawable != null ) { setWillNotDraw ( false ) ; drawable . setCallback ( this ) ; if ( drawable . isStateful ( ) ) { drawable . setState ( getDrawableState ( ) ) ; } if ( mForegroundGravity == Gravity . FILL ) { Rect padding = new Rect ( ) ; drawable . getPadding ( padding ) ; } } else { setWillNotDraw ( true ) ; } requestLayout ( ) ; invalidate ( ) ; } } | Supply a Drawable that is to be rendered on top of all of the child views in the frame layout . Any padding in the Drawable will be taken into account by ensuring that the children are inset to be placed inside of the padding area . |
19,318 | 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 { fos . write ( data ) ; code = IO_SUCCESS ; } catch ( IOException e ) { code = IO_FAIL ; } finally { fos . close ( ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } return code ; } | Dump Data straight to the SDCard |
19,319 | public static Bitmap getVideoThumbnail ( String videoPath ) { MediaMetadataRetriever mmr = new MediaMetadataRetriever ( ) ; mmr . setDataSource ( videoPath ) ; return mmr . getFrameAtTime ( ) ; } | Get a thumbnail bitmap for a given video |
19,320 | public static void getVideoThumbnail ( String videoPath , final VideoThumbnailCallback cb ) { new AsyncTask < String , Void , Bitmap > ( ) { protected Bitmap doInBackground ( String ... params ) { if ( params . length > 0 ) { String path = params [ 0 ] ; if ( ! TextUtils . isEmpty ( path ) ) { return getVideoThumbnail ( path ) ; } } return null ; } protected void onPostExecute ( Bitmap bitmap ) { cb . onThumbnail ( bitmap ) ; } } . execute ( videoPath ) ; } | Get the thumbnail of a video asynchronously |
19,321 | public static boolean copy ( File source , File output ) { if ( output . exists ( ) && output . canWrite ( ) ) { if ( output . delete ( ) ) { try { output . createNewFile ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } else if ( ! output . exists ( ) ) { try { output . createNewFile ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } if ( source . exists ( ) && source . canRead ( ) ) { try { FileInputStream fis = new FileInputStream ( source ) ; FileOutputStream fos = new FileOutputStream ( output ) ; byte [ ] buffer = new byte [ 1024 ] ; int len = 0 ; while ( ( len = fis . read ( buffer ) ) > 0 ) { fos . write ( buffer , 0 , len ) ; } fis . close ( ) ; fos . close ( ) ; return true ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return false ; } | Copy a file from it s source input to the specified output file if it can . |
19,322 | public static String fancyTimestamp ( long epoch ) { if ( System . currentTimeMillis ( ) - epoch < 60000 ) { return "Just now" ; } Calendar now = Calendar . getInstance ( ) ; Calendar cal = Calendar . getInstance ( ) ; cal . setTimeInMillis ( epoch ) ; if ( cal . get ( YEAR ) == now . get ( YEAR ) ) { if ( cal . get ( MONTH ) == now . get ( MONTH ) ) { if ( cal . get ( DAY_OF_MONTH ) == now . get ( DAY_OF_MONTH ) ) { SimpleDateFormat format = new SimpleDateFormat ( "h:mm a" ) ; return format . format ( cal . getTime ( ) ) ; } else { SimpleDateFormat format = new SimpleDateFormat ( "EEE, h:mm a" ) ; return format . format ( cal . getTime ( ) ) ; } } else { SimpleDateFormat format = new SimpleDateFormat ( "EEE, MMM d, h:mm a" ) ; return format . format ( cal . getTime ( ) ) ; } } else { SimpleDateFormat format = new SimpleDateFormat ( "M/d/yy" ) ; return format . format ( cal . getTime ( ) ) ; } } | Generate a fancy timestamp based on unix epoch time that is more user friendly than just a raw output by collapsing the time into manageable formats based on how much time has elapsed since epoch |
19,323 | 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 . getOffset ( now ) ; long dayOrd = localTimestamp / 86400000L ; long nowOrd = localTime / 86400000L ; if ( dayOrd == nowOrd ) { return context . getString ( R . string . day_title_today ) ; } else if ( dayOrd == nowOrd - 1 ) { return context . getString ( R . string . day_title_yesterday ) ; } else if ( dayOrd == nowOrd + 1 ) { return context . getString ( R . string . day_title_tomorrow ) ; } else { return formatShortDate ( context , new Date ( timestamp ) ) ; } } | Returns Today Tomorrow Yesterday or a short date format . |
19,324 | public static boolean isColorDark ( int color ) { return ( ( 30 * Color . red ( color ) + 59 * Color . green ( color ) + 11 * Color . blue ( color ) ) / 100 ) <= BRIGHTNESS_THRESHOLD ; } | Calculate whether a color is light or dark based on a commonly known brightness formula . |
19,325 | public View getView ( int position , View convertView , ViewGroup parent ) { VH holder ; if ( convertView == null ) { convertView = inflater . inflate ( viewResource , parent , false ) ; holder = createHolder ( convertView ) ; convertView . setTag ( holder ) ; } else { holder = ( VH ) convertView . getTag ( ) ; } bindHolder ( holder , position , getItem ( position ) ) ; return convertView ; } | Called to retrieve the view |
19,326 | private static boolean validateVersion ( Context ctx , ChangeLog clog ) { SharedPreferences prefs = PreferenceManager . getDefaultSharedPreferences ( ctx ) ; int lastSeen = prefs . getInt ( PREF_CHANGELOG_LAST_SEEN , - 1 ) ; int latest = Integer . MIN_VALUE ; for ( Version version : clog . versions ) { if ( version . code > latest ) { latest = version . code ; } } if ( latest > lastSeen ) { if ( ! BuildConfig . DEBUG ) prefs . edit ( ) . putInt ( PREF_CHANGELOG_LAST_SEEN , latest ) . apply ( ) ; return true ; } return false ; } | Validate the last seen stored verion code against the current changelog configuration to see if there is any updates and whether or not we should show the changelog dialog when called . |
19,327 | public void enableWatcher ( TextWatcher watcher , boolean enabled ) { int index = mWatchers . indexOfValue ( watcher ) ; if ( index >= 0 ) { int key = mWatchers . keyAt ( index ) ; mEnabledKeys . put ( key , enabled ) ; } } | Enable or Disable a text watcher by reference |
19,328 | 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 ) { mEmptyMessageColor = defaultColor ; mEmptyActionColor = defaultColor ; mEmptyMessageTextSize = ( int ) SizeUtils . dpToPx ( context , 18 ) ; mEmptyActionTextSize = ( int ) SizeUtils . dpToPx ( context , 14 ) ; mEmptyMessageTypeface = Face . ROBOTO_REGULAR ; mEmptyIconPadding = getResources ( ) . getDimensionPixelSize ( R . dimen . activity_padding ) ; return ; } mEmptyIcon = a . getResourceId ( R . styleable . EmptyView_emptyIcon , - 1 ) ; mEmptyIconSize = a . getDimensionPixelSize ( R . styleable . EmptyView_emptyIconSize , - 1 ) ; mEmptyIconColor = a . getColor ( R . styleable . EmptyView_emptyIconColor , defaultColor ) ; mEmptyIconPadding = a . getDimensionPixelSize ( R . styleable . EmptyView_emptyIconPadding , getResources ( ) . getDimensionPixelSize ( R . dimen . activity_padding ) ) ; mEmptyMessage = a . getString ( R . styleable . EmptyView_emptyMessage ) ; mEmptyMessageColor = a . getColor ( R . styleable . EmptyView_emptyMessageColor , defaultColor ) ; int typeface = a . getInt ( R . styleable . EmptyView_emptyMessageTypeface , 0 ) ; mEmptyMessageTypeface = MessageTypeface . from ( typeface ) . getTypeface ( ) ; mEmptyMessageTextSize = a . getDimensionPixelSize ( R . styleable . EmptyView_emptyMessageTextSize , ( int ) SizeUtils . dpToPx ( context , 18 ) ) ; mEmptyActionColor = a . getColor ( R . styleable . EmptyView_emptyActionColor , defaultColor ) ; mEmptyActionText = a . getString ( R . styleable . EmptyView_emptyActionText ) ; mEmptyActionTextSize = a . getDimensionPixelSize ( R . styleable . EmptyView_emptyActionTextSize , ( int ) SizeUtils . dpToPx ( context , 14 ) ) ; mState = a . getInt ( R . styleable . EmptyView_emptyState , STATE_EMPTY ) ; a . recycle ( ) ; } | Parse XML attributes |
19,329 | public void setIcon ( Drawable drawable ) { mIcon . setImageDrawable ( drawable ) ; mIcon . setVisibility ( View . VISIBLE ) ; } | Set the icon for this empty view |
19,330 | 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 ) ; mIcon . setLayoutParams ( iconParams ) ; } | Set the size of the icon in the center of the view |
19,331 | public void setActionLabel ( CharSequence label ) { mEmptyActionText = label ; mAction . setText ( mEmptyActionText ) ; mAction . setVisibility ( TextUtils . isEmpty ( mEmptyActionText ) ? View . GONE : View . VISIBLE ) ; } | Set the action button label this in - turn enables it . Pass null to disable . |
19,332 | public void setLoading ( ) { mState = STATE_LOADING ; mProgress . setVisibility ( View . VISIBLE ) ; mAction . setVisibility ( View . GONE ) ; mMessage . setVisibility ( View . GONE ) ; mIcon . setVisibility ( View . GONE ) ; } | Set this view to loading state to show a loading indicator and hide the other parts of this view . |
19,333 | 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 . setVisibility ( View . VISIBLE ) ; } | Set this view to it s empty state showing the icon message and action if configured |
19,334 | private View getNextView ( RecyclerView parent ) { View firstView = parent . getChildAt ( 0 ) ; int firstPosition = parent . getChildPosition ( firstView ) ; View firstHeader = getHeaderView ( parent , firstPosition ) ; for ( int i = 0 ; i < parent . getChildCount ( ) ; i ++ ) { View child = parent . getChildAt ( i ) ; RecyclerView . LayoutParams layoutParams = ( RecyclerView . LayoutParams ) child . getLayoutParams ( ) ; if ( getOrientation ( parent ) == LinearLayoutManager . VERTICAL ) { if ( child . getTop ( ) - layoutParams . topMargin > firstHeader . getHeight ( ) ) { return child ; } } else { if ( child . getLeft ( ) - layoutParams . leftMargin > firstHeader . getWidth ( ) ) { return child ; } } } return null ; } | Returns the first item currently in the recyclerview that s not obscured by a header . |
19,335 | @ SuppressLint ( "NewApi" ) private void buildAndAttach ( ) { mActivity . overridePendingTransition ( 0 , 0 ) ; if ( BuildUtils . isLollipop ( ) ) { Window window = mActivity . getWindow ( ) ; window . addFlags ( FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS ) ; window . setStatusBarColor ( Color . TRANSPARENT ) ; } hiJackDecor ( ) ; setupDrawer ( ) ; populateNavDrawer ( ) ; } | Build the nav drawer layout inflate it then attach it to the activity |
19,336 | private void setupDrawer ( ) { int backgroundColor = UIUtils . getColorAttr ( mActivity , R . attr . drawerBackground ) ; if ( backgroundColor > 0 ) { mDrawerPane . setBackgroundColor ( backgroundColor ) ; } int statusBarColor = mConfig . getStatusBarColor ( mActivity ) ; if ( statusBarColor != - 1 ) mDrawerLayout . setStatusBarBackgroundColor ( statusBarColor ) ; populateHeader ( ) ; populateFooter ( ) ; final int headerHeight = mActivity . getResources ( ) . getDimensionPixelSize ( R . dimen . navdrawer_chosen_account_height ) ; mDrawerPane . setOnInsetsCallback ( new OnInsetsCallback ( ) { public void onInsetsChanged ( Rect insets ) { if ( mHeaderView != null ) { mConfig . onInsetsChanged ( mHeaderView , insets ) ; ViewGroup . LayoutParams lp2 = mDrawerHeaderFrame . getLayoutParams ( ) ; lp2 . height = headerHeight + insets . top ; mDrawerHeaderFrame . setLayoutParams ( lp2 ) ; } else { ViewGroup . LayoutParams lp2 = mDrawerHeaderFrame . getLayoutParams ( ) ; lp2 . height = insets . top ; mDrawerHeaderFrame . setLayoutParams ( lp2 ) ; } } } ) ; if ( mToolbar != null ) { mDrawerToggle = new ActionBarDrawerToggle ( mActivity , mDrawerLayout , mToolbar , R . string . navigation_drawer_open , R . string . navigation_drawer_close ) { public void onDrawerClosed ( View drawerView ) { super . onDrawerClosed ( drawerView ) ; if ( mCallbacks != null ) mCallbacks . onDrawerClosed ( drawerView ) ; } public void onDrawerOpened ( View drawerView ) { super . onDrawerOpened ( drawerView ) ; if ( mCallbacks != null ) mCallbacks . onDrawerOpened ( drawerView ) ; } public void onDrawerSlide ( View drawerView , float slideOffset ) { super . onDrawerSlide ( drawerView , mConfig . shouldAnimateIndicator ( ) ? slideOffset : 0 ) ; if ( mCallbacks != null ) mCallbacks . onDrawerSlide ( drawerView , slideOffset ) ; } } ; mDrawerLayout . post ( new Runnable ( ) { public void run ( ) { mDrawerToggle . syncState ( ) ; } } ) ; mDrawerLayout . setDrawerListener ( mDrawerToggle ) ; } mDrawerLayout . setDrawerShadow ( R . drawable . drawer_shadow , GravityCompat . START ) ; } | Setup the navigation drawer layout and whatnot |
19,337 | private void createNavDrawerItems ( ) { if ( mDrawerItemsListContainer == null ) { return ; } mNavDrawerItemViews . clear ( ) ; mDrawerItemsListContainer . removeAllViews ( ) ; for ( DrawerItem item : mDrawerItems ) { item . setSelected ( item . getId ( ) == mSelectedItem ) ; View view = item . onCreateView ( mActivity . getLayoutInflater ( ) , mDrawerItemsListContainer , mConfig . getItemHighlightColor ( mActivity ) ) ; if ( ! ( item instanceof SeperatorDrawerItem ) ) { view . setId ( item . getId ( ) ) ; mNavDrawerItemViews . put ( item . getId ( ) , view ) ; mNavDrawerItems . put ( item . getId ( ) , item ) ; if ( ! ( item instanceof SwitchDrawerItem ) ) { view . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { onNavDrawerItemClicked ( v . getId ( ) ) ; } } ) ; } } mDrawerItemsListContainer . addView ( view ) ; } } | Populate the nav drawer items into the view |
19,338 | private void onNavDrawerItemClicked ( final int itemId ) { if ( itemId == mSelectedItem ) { mDrawerLayout . closeDrawer ( GravityCompat . START ) ; return ; } if ( isSpecialItem ( itemId ) ) { goToNavDrawerItem ( itemId ) ; } else { mHandler . postDelayed ( new Runnable ( ) { public void run ( ) { goToNavDrawerItem ( itemId ) ; } } , mConfig . getLaunchDelay ( ) ) ; setSelectedNavDrawerItem ( itemId ) ; } mDrawerLayout . closeDrawer ( GravityCompat . START ) ; } | Call when a nav drawer item is clicked |
19,339 | private void formatNavDrawerItem ( DrawerItem item , boolean selected ) { if ( item instanceof SeperatorDrawerItem || item instanceof SwitchDrawerItem ) { return ; } View view = mNavDrawerItemViews . get ( item . getId ( ) ) ; ImageView iconView = ( ImageView ) view . findViewById ( R . id . icon ) ; TextView titleView = ( TextView ) view . findViewById ( R . id . title ) ; titleView . setTextColor ( selected ? mConfig . getItemHighlightColor ( mActivity ) : UIUtils . getColorAttr ( mActivity , android . R . attr . textColorPrimary ) ) ; iconView . setColorFilter ( selected ? mConfig . getItemHighlightColor ( mActivity ) : getResources ( ) . getColor ( R . color . navdrawer_icon_tint ) , PorterDuff . Mode . SRC_ATOP ) ; } | Format a nav drawer item based on current selected states |
19,340 | private DrawerLayout inflateDrawerLayout ( ViewGroup parent ) { DrawerLayout drawer = ( DrawerLayout ) mActivity . getLayoutInflater ( ) . inflate ( R . layout . material_drawer , parent , false ) ; mDrawerPane = ButterKnife . findById ( drawer , R . id . navdrawer ) ; mDrawerContentFrame = ButterKnife . findById ( drawer , R . id . drawer_content_frame ) ; mDrawerHeaderFrame = ButterKnife . findById ( mDrawerPane , R . id . header_container ) ; mDrawerFooterFrame = ButterKnife . findById ( mDrawerPane , R . id . footer ) ; mDrawerItemsListContainer = ButterKnife . findById ( mDrawerPane , R . id . navdrawer_items_list ) ; return drawer ; } | Build the root drawer layout |
19,341 | 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 ( ) ) / ( ( float ) drawable . getIntrinsicWidth ( ) ) ) ) ; setMeasuredDimension ( width , height ) ; } else if ( ratioType == RATIO_HEIGHT ) { int height = MeasureSpec . getSize ( heightMeasureSpec ) ; int width = Math . round ( height * ( ( float ) drawable . getIntrinsicWidth ( ) ) / ( ( float ) drawable . getIntrinsicHeight ( ) ) ) ; setMeasuredDimension ( width , height ) ; } } else { super . onMeasure ( widthMeasureSpec , heightMeasureSpec ) ; } } | Maintain Image Aspect Ratio no matter the size |
19,342 | 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 ; } | Get the status bar height |
19,343 | protected void onItemClick ( View view , int position ) { if ( itemClickListener != null ) itemClickListener . onItemClick ( view , getItem ( position ) , position ) ; } | Call this to trigger the user set item click listener |
19,344 | protected void onItemLongClick ( View view , int position ) { if ( itemLongClickListener != null ) itemLongClickListener . onItemLongClick ( view , getItem ( position ) , position ) ; } | Call this to trigger the user set item long click lisetner |
19,345 | public void setEmptyView ( View emptyView ) { if ( this . emptyView != null ) { unregisterAdapterDataObserver ( mEmptyObserver ) ; } this . emptyView = emptyView ; registerAdapterDataObserver ( mEmptyObserver ) ; } | Set the empty view to be used so that |
19,346 | private void checkIfEmpty ( ) { if ( emptyView != null ) { emptyView . setVisibility ( getItemCount ( ) > 0 ? View . GONE : View . VISIBLE ) ; } } | Check if we should show the empty view |
19,347 | public void addAll ( Collection < ? extends M > collection ) { if ( collection != null ) { items . addAll ( collection ) ; applyFilter ( ) ; } } | Add a collection of objects to this adapter |
19,348 | public M remove ( int index ) { M item = items . remove ( index ) ; applyFilter ( ) ; return item ; } | Remove an item at the given index |
19,349 | 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 ( ) ; onItemMoved ( startItem , realStart , realEnd ) ; notifyItemMoved ( realStart , realEnd ) ; } | Move an item around in the underlying array |
19,350 | 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 ) ) { filteredItems . add ( item ) ; } } } onFiltered ( ) ; } | Apply the filter if possible to the adapter to update content |
19,351 | public void onBindViewHolder ( final VH vh , final int i ) { if ( itemClickListener != null ) { vh . itemView . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { int position = vh . getAdapterPosition ( ) ; if ( position != RecyclerView . NO_POSITION ) { itemClickListener . onItemClick ( v , getItem ( position ) , position ) ; } } } ) ; } if ( itemLongClickListener != null ) { vh . itemView . setOnLongClickListener ( new View . OnLongClickListener ( ) { public boolean onLongClick ( View v ) { int position = vh . getAdapterPosition ( ) ; if ( position != RecyclerView . NO_POSITION ) { return itemLongClickListener . onItemLongClick ( v , getItem ( position ) , position ) ; } return false ; } } ) ; } } | Intercept the bind View holder method to wire up the item click listener only if the listener is set by the user |
19,352 | 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 ; } | Get the item Id for a given position |
19,353 | 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 ; } | Generate a pre - populated intent to launch this activity with |
19,354 | public String getLicenseText ( ) { if ( license != null ) { return license . getLicense ( description , year , author , email ) ; } return "N/A" ; } | Get the formatted license text for display |
19,355 | public static Intent getCameraCaptureIntent ( Context ctx , String authority ) { Intent intent = new Intent ( MediaStore . ACTION_IMAGE_CAPTURE ) ; try { mCurrentCaptureUri = createAccessibleTempFile ( ctx , authority ) ; grantPermissions ( ctx , mCurrentCaptureUri ) ; intent . putExtra ( MediaStore . EXTRA_OUTPUT , mCurrentCaptureUri ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return intent ; } | Generate the appropriate intent to launch the existing camera application to capture an image |
19,356 | public static Intent getChooseMediaIntent ( String mimeType ) { Intent intent = new Intent ( Intent . ACTION_GET_CONTENT ) ; intent . addCategory ( Intent . CATEGORY_OPENABLE ) ; intent . setType ( mimeType ) ; return intent ; } | Generate the appropriate intent to launch the document chooser to allow the user to pick an image to upload . |
19,357 | 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 ) { revokePermissions ( context , mCurrentCaptureUri ) ; File file = getAccessibleTempFile ( context , mCurrentCaptureUri ) ; mCurrentCaptureUri = null ; return Observable . just ( file ) ; } return Observable . error ( new FileNotFoundException ( "Unable to find camera capture" ) ) ; case PICK_MEDIA_REQUEST_CODE : final Uri mediaUri = data . getData ( ) ; final String fileName = getFileName ( context , mediaUri ) ; if ( mediaUri != null ) { return Observable . fromCallable ( new Callable < File > ( ) { public File call ( ) throws Exception { ParcelFileDescriptor parcelFileDescriptor = null ; try { parcelFileDescriptor = context . getContentResolver ( ) . openFileDescriptor ( mediaUri , "r" ) ; FileDescriptor fileDescriptor = parcelFileDescriptor . getFileDescriptor ( ) ; FileInputStream fis = new FileInputStream ( fileDescriptor ) ; FileOutputStream fos = null ; try { File tempFile = createTempFile ( context , fileName ) ; fos = new FileOutputStream ( tempFile ) ; byte [ ] buffer = new byte [ 1024 ] ; int len ; while ( ( len = fis . read ( buffer ) ) > 0 ) { fos . write ( buffer , 0 , len ) ; } return tempFile ; } catch ( IOException e ) { throw OnErrorThrowable . from ( e ) ; } finally { try { parcelFileDescriptor . close ( ) ; fis . close ( ) ; if ( fos != null ) { fos . close ( ) ; } } catch ( IOException e1 ) { e1 . printStackTrace ( ) ; } } } catch ( FileNotFoundException e ) { throw OnErrorThrowable . from ( e ) ; } } } ) . compose ( RxUtils . < File > applyWorkSchedulers ( ) ) ; } return Observable . error ( new FileNotFoundException ( "Unable to load selected file" ) ) ; default : return Observable . empty ( ) ; } } return Observable . empty ( ) ; } | Handle the activity result of an intent launched to capture a photo or choose an image |
19,358 | private static Uri createAccessibleTempFile ( Context ctx , String authority ) throws IOException { File dir = new File ( ctx . getCacheDir ( ) , "camera" ) ; File tmp = createTempFile ( dir ) ; return FileProvider . getUriForFile ( ctx , authority , tmp ) ; } | Generate an accessible temporary file URI to be used for camera captures |
19,359 | 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 : resolvedIntentActivities ) { String packageName = resolvedIntentInfo . activityInfo . packageName ; ctx . grantUriPermission ( packageName , uri , Intent . FLAG_GRANT_WRITE_URI_PERMISSION | Intent . FLAG_GRANT_READ_URI_PERMISSION ) ; } } | Grant URI permissions for all potential camera applications that can handle the capture intent . |
19,360 | private static void revokePermissions ( Context ctx , Uri uri ) { ctx . revokeUriPermission ( uri , Intent . FLAG_GRANT_WRITE_URI_PERMISSION | Intent . FLAG_GRANT_READ_URI_PERMISSION ) ; } | Revoke URI permissions to a specific URI that had been previously granted |
19,361 | public static String cleanFilename ( String fileName ) { int lastIndex = fileName . lastIndexOf ( "." ) ; return fileName . substring ( 0 , lastIndex ) ; } | Clean the extension off of the file name . |
19,362 | 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 ) ; } | Return whether or not the current device is an emulator |
19,363 | public static int getGMTOffset ( ) { Calendar now = Calendar . getInstance ( ) ; return ( now . get ( Calendar . ZONE_OFFSET ) + now . get ( Calendar . DST_OFFSET ) ) / 3600000 ; } | Get the Device s GMT Offset |
19,364 | 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 ; } | Get the MIME type of a file |
19,365 | 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 ) ) ; } | Compute the distance between two points |
19,366 | public static float parseFloat ( String val , float defVal ) { if ( TextUtils . isEmpty ( val ) ) return defVal ; try { return Float . parseFloat ( val ) ; } catch ( NumberFormatException e ) { return defVal ; } } | Parse a float from a String in a safe manner . |
19,367 | public static int parseInt ( String val , int defValue ) { if ( TextUtils . isEmpty ( val ) ) return defValue ; try { return Integer . parseInt ( val ) ; } catch ( NumberFormatException e ) { return defValue ; } } | Parse a int from a String in a safe manner . |
19,368 | public static long parseLong ( String val , long defValue ) { if ( TextUtils . isEmpty ( val ) ) return defValue ; try { return Long . parseLong ( val ) ; } catch ( NumberFormatException e ) { return defValue ; } } | Parse a long from a String in a safe manner . |
19,369 | public static double parseDouble ( String val , double defValue ) { if ( TextUtils . isEmpty ( val ) ) return defValue ; try { return Double . parseDouble ( val ) ; } catch ( NumberFormatException e ) { return defValue ; } } | Parse a double from a String in a safe manner |
19,370 | private void configAppBar ( ) { setSupportActionBar ( mAppbar ) ; getSupportActionBar ( ) . setDisplayHomeAsUpEnabled ( true ) ; getSupportActionBar ( ) . setTitle ( R . string . changelog_activity_title ) ; mAppbar . setNavigationOnClickListener ( this ) ; } | Configure the Appbar |
19,371 | public static void apply ( TextView textView , Face type ) { Typeface typeface = getTypeface ( textView . getContext ( ) , type ) ; if ( typeface != null ) textView . setTypeface ( typeface ) ; } | Apply a typeface to a textview |
19,372 | 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 ) ; } } | Apply a typeface to one or many textviews |
19,373 | public static Typeface getTypeface ( Context ctx , Face type ) { return getTypeface ( ctx , "fonts/" + type . getFontFileName ( ) ) ; } | Get a Roboto typeface for a given string type |
19,374 | public void start ( ) { eb = vertx . eventBus ( ) ; config = config ( ) ; FileResolver . getInstance ( ) . setBasePath ( config ) ; } | Start the busmod |
19,375 | public Plan makeSelectPlan ( ) { Plan p = makeIndexSelectPlan ( ) ; if ( p == null ) p = tp ; return addSelectPredicate ( p ) ; } | Constructs a select plan for the table . The plan will use an indexselect if possible . |
19,376 | 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 ; } | Constructs a join plan of the specified trunk and this table . The plan will use an indexjoin if possible ; otherwise a multi - buffer product join . The method returns null if no join is possible . |
19,377 | public Plan makeProductPlan ( Plan trunk ) { Plan p = makeSelectPlan ( ) ; return new MultiBufferProductPlan ( trunk , p , tx ) ; } | Constructs a product plan of the specified trunk and this table . |
19,378 | public AccountService getAccountService ( ) { if ( _accountService == null ) { synchronized ( CCApi2 . class ) { if ( _accountService == null ) { _accountService = _retrofit . create ( AccountService . class ) ; } } } return _accountService ; } | Gets the account service . |
19,379 | public CampaignService getCampaignService ( ) { if ( _campaignService == null ) { synchronized ( CCApi2 . class ) { if ( _campaignService == null ) { _campaignService = _retrofit . create ( CampaignService . class ) ; } } } return _campaignService ; } | Gets the campaign service . |
19,380 | public ContactService getContactService ( ) { if ( _contactService == null ) { synchronized ( CCApi2 . class ) { if ( _contactService == null ) { _contactService = _retrofit . create ( ContactService . class ) ; } } } return _contactService ; } | Gets the contact service . |
19,381 | public LibraryService getLibraryService ( ) { if ( _libraryService == null ) { synchronized ( CCApi2 . class ) { if ( _libraryService == null ) { _libraryService = _retrofit . create ( LibraryService . class ) ; } } } return _libraryService ; } | Gets the library service . |
19,382 | public CampaignTrackingService getCampaignTrackingService ( ) { if ( _campaignTrackingService == null ) { synchronized ( CCApi2 . class ) { if ( _campaignTrackingService == null ) { _campaignTrackingService = _retrofit . create ( CampaignTrackingService . class ) ; } } } return _campaignTrackingService ; } | Gets the campaign tracking service . |
19,383 | public ContactTrackingService getContactTrackingService ( ) { if ( _contactTrackingService == null ) { synchronized ( CCApi2 . class ) { if ( _contactTrackingService == null ) { _contactTrackingService = _retrofit . create ( ContactTrackingService . class ) ; } } } return _contactTrackingService ; } | Gets the contact tracking service . |
19,384 | public BulkActivitiesService getBulkActivitiesService ( ) { if ( _bulkActivitiesService == null ) { synchronized ( CCApi2 . class ) { if ( _bulkActivitiesService == null ) { _bulkActivitiesService = _retrofit . create ( BulkActivitiesService . class ) ; } } } return _bulkActivitiesService ; } | Gets the bulk activities service . |
19,385 | public void createTable ( String tblName , Schema sch , Transaction tx ) { if ( tblName != TCAT_TBLNAME && tblName != FCAT_TBLNAME ) formatFileHeader ( tblName , tx ) ; tiMap . put ( tblName , new TableInfo ( tblName , sch ) ) ; RecordFile tcatfile = tcatInfo . open ( tx , true ) ; tcatfile . insert ( ) ; tcatfile . setVal ( TCAT_TBLNAME , new VarcharConstant ( tblName ) ) ; tcatfile . close ( ) ; RecordFile fcatfile = fcatInfo . open ( tx , true ) ; for ( String fldname : sch . fields ( ) ) { fcatfile . insert ( ) ; fcatfile . setVal ( FCAT_TBLNAME , new VarcharConstant ( tblName ) ) ; fcatfile . setVal ( FCAT_FLDNAME , new VarcharConstant ( fldname ) ) ; fcatfile . setVal ( FCAT_TYPE , new IntegerConstant ( sch . type ( fldname ) . getSqlType ( ) ) ) ; fcatfile . setVal ( FCAT_TYPEARG , new IntegerConstant ( sch . type ( fldname ) . getArgument ( ) ) ) ; } fcatfile . close ( ) ; } | Creates a new table having the specified name and schema . |
19,386 | public void dropTable ( String tblName , Transaction tx ) { RecordFile rf = getTableInfo ( tblName , tx ) . open ( tx , true ) ; rf . remove ( ) ; tiMap . remove ( tblName ) ; RecordFile tcatfile = tcatInfo . open ( tx , true ) ; tcatfile . beforeFirst ( ) ; while ( tcatfile . next ( ) ) { if ( tcatfile . getVal ( TCAT_TBLNAME ) . equals ( new VarcharConstant ( tblName ) ) ) { tcatfile . delete ( ) ; break ; } } tcatfile . close ( ) ; RecordFile fcatfile = fcatInfo . open ( tx , true ) ; fcatfile . beforeFirst ( ) ; while ( fcatfile . next ( ) ) { if ( fcatfile . getVal ( FCAT_TBLNAME ) . equals ( new VarcharConstant ( tblName ) ) ) fcatfile . delete ( ) ; } fcatfile . close ( ) ; List < IndexInfo > allIndexes = new LinkedList < IndexInfo > ( ) ; Set < String > indexedFlds = VanillaDb . catalogMgr ( ) . getIndexedFields ( tblName , tx ) ; for ( String indexedFld : indexedFlds ) { List < IndexInfo > iis = VanillaDb . catalogMgr ( ) . getIndexInfo ( tblName , indexedFld , tx ) ; allIndexes . addAll ( iis ) ; } for ( IndexInfo ii : allIndexes ) VanillaDb . catalogMgr ( ) . dropIndex ( ii . indexName ( ) , tx ) ; Collection < String > vnames = VanillaDb . catalogMgr ( ) . getViewNamesByTable ( tblName , tx ) ; Iterator < String > vnameiter = vnames . iterator ( ) ; while ( vnameiter . hasNext ( ) ) VanillaDb . catalogMgr ( ) . dropView ( vnameiter . next ( ) , tx ) ; } | Remove a table with the specified name . |
19,387 | public TableInfo getTableInfo ( String tblName , Transaction tx ) { 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 = ( String ) tcatfile . getVal ( TCAT_TBLNAME ) . asJavaVal ( ) ; if ( t . equals ( tblName ) ) { found = true ; break ; } } tcatfile . close ( ) ; if ( ! found ) return null ; RecordFile fcatfile = fcatInfo . open ( tx , true ) ; fcatfile . beforeFirst ( ) ; Schema sch = new Schema ( ) ; while ( fcatfile . next ( ) ) if ( ( ( String ) fcatfile . getVal ( FCAT_TBLNAME ) . asJavaVal ( ) ) . equals ( tblName ) ) { String fldname = ( String ) fcatfile . getVal ( FCAT_FLDNAME ) . asJavaVal ( ) ; int fldtype = ( Integer ) fcatfile . getVal ( FCAT_TYPE ) . asJavaVal ( ) ; int fldarg = ( Integer ) fcatfile . getVal ( FCAT_TYPEARG ) . asJavaVal ( ) ; sch . addField ( fldname , Type . newInstance ( fldtype , fldarg ) ) ; } fcatfile . close ( ) ; resultTi = new TableInfo ( tblName , sch ) ; tiMap . put ( tblName , resultTi ) ; return resultTi ; } | Retrieves the metadata for the specified table out of the catalog . |
19,388 | public static void startUp ( int port ) throws Exception { Registry reg = LocateRegistry . createRegistry ( port ) ; RemoteDriver d = new RemoteDriverImpl ( ) ; reg . rebind ( "vanilladb-sp" , d ) ; } | Starts up the stored procedure call driver in server side by binding the remote driver object to local registry . |
19,389 | public Scan open ( ) { Scan src = p . open ( ) ; List < TempTable > runs = splitIntoRuns ( src ) ; if ( runs . size ( ) == 0 ) return src ; src . close ( ) ; while ( runs . size ( ) > 2 ) runs = doAMergeIteration ( runs ) ; return new SortScan ( runs , comp ) ; } | This method is where most of the action is . Up to 2 sorted temporary tables are created and are passed into SortScan for final merging . |
19,390 | 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 ; } } | Moves the scan to the next record . The method moves to the next RHS record if possible . Otherwise it moves to the next LHS record and the first RHS record . If there are no more LHS records the method returns false . |
19,391 | 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 ) && ! waitingTooLong ( timestamp ) ) { avoidDeadlock ( lks , txNum , S_LOCK ) ; lks . requestSet . add ( txNum ) ; anchor . wait ( MAX_TIME ) ; lks . requestSet . remove ( txNum ) ; } if ( ! sLockable ( lks , txNum ) ) throw new LockAbortException ( ) ; lks . sLockers . add ( txNum ) ; getObjectSet ( txNum ) . add ( obj ) ; } catch ( InterruptedException e ) { throw new LockAbortException ( "abort tx." + txNum + " by interrupted" ) ; } } txWaitMap . remove ( txNum ) ; } | Grants an slock on the specified item . If any conflict lock exists when the method is called then the calling thread will be placed on a wait list until the lock is released . If the thread remains on the wait list for a certain amount of time then an exception is thrown . |
19,392 | 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 ) && ! waitingTooLong ( timestamp ) ) { avoidDeadlock ( lks , txNum , X_LOCK ) ; lks . requestSet . add ( txNum ) ; anchor . wait ( MAX_TIME ) ; lks . requestSet . remove ( txNum ) ; } if ( ! xLockable ( lks , txNum ) ) throw new LockAbortException ( ) ; lks . xLocker = txNum ; getObjectSet ( txNum ) . add ( obj ) ; } catch ( InterruptedException e ) { throw new LockAbortException ( ) ; } } txWaitMap . remove ( txNum ) ; } | Grants an xlock on the specified item . If any conflict lock exists when the method is called then the calling thread will be placed on a wait list until the lock is released . If the thread remains on the wait list for a certain amount of time then an exception is thrown . |
19,393 | 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 ) && ! waitingTooLong ( timestamp ) ) { avoidDeadlock ( lks , txNum , SIX_LOCK ) ; lks . requestSet . add ( txNum ) ; anchor . wait ( MAX_TIME ) ; lks . requestSet . remove ( txNum ) ; } if ( ! sixLockable ( lks , txNum ) ) throw new LockAbortException ( ) ; lks . sixLocker = txNum ; getObjectSet ( txNum ) . add ( obj ) ; } catch ( InterruptedException e ) { throw new LockAbortException ( ) ; } } txWaitMap . remove ( txNum ) ; } | Grants an sixlock on the specified item . If any conflict lock exists when the method is called then the calling thread will be placed on a wait list until the lock is released . If the thread remains on the wait list for a certain amount of time then an exception is thrown . |
19,394 | 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 ) && ! waitingTooLong ( timestamp ) ) { avoidDeadlock ( lks , txNum , IS_LOCK ) ; lks . requestSet . add ( txNum ) ; anchor . wait ( MAX_TIME ) ; lks . requestSet . remove ( txNum ) ; } if ( ! isLockable ( lks , txNum ) ) throw new LockAbortException ( ) ; lks . isLockers . add ( txNum ) ; getObjectSet ( txNum ) . add ( obj ) ; } catch ( InterruptedException e ) { throw new LockAbortException ( ) ; } } txWaitMap . remove ( txNum ) ; } | Grants an islock on the specified item . If any conflict lock exists when the method is called then the calling thread will be placed on a wait list until the lock is released . If the thread remains on the wait list for a certain amount of time then an exception is thrown . |
19,395 | 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 ) && ! waitingTooLong ( timestamp ) ) { avoidDeadlock ( lks , txNum , IX_LOCK ) ; lks . requestSet . add ( txNum ) ; anchor . wait ( MAX_TIME ) ; lks . requestSet . remove ( txNum ) ; } if ( ! ixLockable ( lks , txNum ) ) throw new LockAbortException ( ) ; lks . ixLockers . add ( txNum ) ; getObjectSet ( txNum ) . add ( obj ) ; } catch ( InterruptedException e ) { throw new LockAbortException ( ) ; } } txWaitMap . remove ( txNum ) ; } | Grants an ixlock on the specified item . If any conflict lock exists when the method is called then the calling thread will be placed on a wait list until the lock is released . If the thread remains on the wait list for a certain amount of time then an exception is thrown . |
19,396 | void release ( Object obj , long txNum , int lockType ) { Object anchor = getAnchor ( obj ) ; synchronized ( anchor ) { Lockers lks = lockerMap . get ( obj ) ; if ( lks != null ) { releaseLock ( lks , anchor , txNum , lockType ) ; if ( ! hasSLock ( lks , txNum ) && ! hasXLock ( lks , txNum ) && ! hasSixLock ( lks , txNum ) && ! hasIsLock ( lks , txNum ) && ! hasIxLock ( lks , txNum ) ) { getObjectSet ( txNum ) . remove ( obj ) ; if ( ! sLocked ( lks ) && ! xLocked ( lks ) && ! sixLocked ( lks ) && ! isLocked ( lks ) && ! ixLocked ( lks ) && lks . requestSet . isEmpty ( ) ) lockerMap . remove ( obj ) ; } } } } | Releases the specified type of lock on an item holding by a transaction . If a lock is the last lock on that block then the waiting transactions are notified . |
19,397 | 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 ) ) releaseLock ( lks , anchor , txNum , S_LOCK ) ; if ( hasXLock ( lks , txNum ) && ! sLockOnly ) releaseLock ( lks , anchor , txNum , X_LOCK ) ; if ( hasSixLock ( lks , txNum ) ) releaseLock ( lks , anchor , txNum , SIX_LOCK ) ; while ( hasIsLock ( lks , txNum ) ) releaseLock ( lks , anchor , txNum , IS_LOCK ) ; while ( hasIxLock ( lks , txNum ) && ! sLockOnly ) releaseLock ( lks , anchor , txNum , IX_LOCK ) ; if ( ! sLocked ( lks ) && ! xLocked ( lks ) && ! sixLocked ( lks ) && ! isLocked ( lks ) && ! ixLocked ( lks ) && lks . requestSet . isEmpty ( ) ) lockerMap . remove ( obj ) ; } } } txWaitMap . remove ( txNum ) ; txnsToBeAborted . remove ( txNum ) ; lockByMap . remove ( txNum ) ; } | Releases all locks held by a transaction . If a lock is the last lock on that block then the waiting transactions are notified . |
19,398 | public void close ( ) { if ( blk != null ) { tx . bufferMgr ( ) . unpin ( currentBuff ) ; blk = null ; currentBuff = null ; } } | Closes the header manager by unpinning the block . |
19,399 | public boolean hasDataRecords ( ) { long blkNum = ( Long ) getVal ( OFFSET_TS_BLOCKID , BIGINT ) . asJavaVal ( ) ; return blkNum != NO_SLOT_BLOCKID ? true : false ; } | Return true if this file has inserted data records . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.