Java Code Examples for android.os.Build

The following examples show how to use android.os.Build. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void createCardView(ViewHolder holder, List<Point> points) {
    for (int i = 0; i < points.size(); i++) {
        final Point point = points.get(i);
        View pointView = LayoutInflater.from(mContext).inflate(R.layout.carview_review, holder.ly_carview, false);
        TextView pointName = (TextView) pointView.findViewById(R.id.tv_carview);
        CardView cardView = (CardView) pointView.findViewById(R.id.cv_carview);
        //5.0CarView 才支持设置阴影
        if(Build.VERSION.SDK_INT >=21) {
            cardView.setElevation(TDevice.dpToPixel(8));
        }
        cardViewSetBackgroundColor(point, cardView);
        //如果不是无效知识点,则加入点击事件
        if (point.getObjectId() != null) {
            cardView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    startContentList(point);
                }
            });
        }
        pointName.setText(point.getName());
        holder.ly_carview.addView(pointView);
    }
}
 
Example 2
@Override
public void onPanelSlide(View panel, float slideOffset) {
  super.onPanelSlide(panel, slideOffset);
  if (partialView == null || fullView == null) {
    return;
  }

  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
    if (slideOffset == 1 && !wasOpened) {
      // the layout was just opened, move the partial view off screen
      updatePartialViewVisibilityPreHoneycomb(true);
      wasOpened = true;
    } else if (slideOffset < 1 && wasOpened) {
      // the layout just started to close, move the partial view back, so it can be shown animating
      updatePartialViewVisibilityPreHoneycomb(false);
      wasOpened = false;
    }
  } else {
    partialView.setVisibility(isOpen() ? View.GONE : VISIBLE);
  }
  
  ViewHelper.setAlpha(partialView, 1 - slideOffset);
  ViewHelper.setAlpha(fullView, slideOffset);
}
 
Example 3
Source Project: UberClone   Source File: CustomerMapActivity.java    License: MIT License 6 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(1000);
    mLocationRequest.setFastestInterval(1000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
        if(ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){

        }else{
            checkLocationPermission();
        }
    }

    mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());
    mMap.setMyLocationEnabled(true);
}
 
Example 4
Source Project: MyBookshelf   Source File: UpdateManager.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 安装apk
 */
public void installApk(File apkFile) {
    if (!apkFile.exists()) {
        return;
    }
    Intent intent = new Intent();
    //执行动作
    intent.setAction(Intent.ACTION_VIEW);
    //判读版本是否在7.0以上
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        Uri apkUri = FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".fileProvider", apkFile);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
    } else {
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
    }
    try {
        activity.startActivity(intent);
    } catch (Exception e) {
        Log.d("wwd", "Failed to launcher installing activity");
    }
}
 
Example 5
Source Project: talk-android   Source File: TextureRenderView.java    License: MIT License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void bindToMediaPlayer(IMediaPlayer mp) {
    if (mp == null)
        return;

    if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) &&
            (mp instanceof ISurfaceTextureHolder)) {
        ISurfaceTextureHolder textureHolder = (ISurfaceTextureHolder) mp;
        mTextureView.mSurfaceCallback.setOwnSurfaceTexture(false);

        SurfaceTexture surfaceTexture = textureHolder.getSurfaceTexture();
        if (surfaceTexture != null) {
            mTextureView.setSurfaceTexture(surfaceTexture);
        } else {
            textureHolder.setSurfaceTexture(mSurfaceTexture);
            textureHolder.setSurfaceTextureHost(mTextureView.mSurfaceCallback);
        }
    } else {
        mp.setSurface(openSurface());
    }
}
 
Example 6
Source Project: DebugDrawer   Source File: DebugDrawer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * helper to extend the layoutParams of the drawer
 *
 * @param params
 * @return
 */
private DrawerLayout.LayoutParams processDrawerLayoutParams(DrawerLayout.LayoutParams params) {
    if (params != null) {
        if (drawerGravity != 0 && (drawerGravity == Gravity.RIGHT || drawerGravity == Gravity.END)) {
            params.rightMargin = 0;
            if (Build.VERSION.SDK_INT >= 17) {
                params.setMarginEnd(0);
            }

            params.leftMargin = activity.getResources().getDimensionPixelSize(R.dimen.dd_debug_drawer_margin);
            if (Build.VERSION.SDK_INT >= 17) {
                params.setMarginEnd(activity.getResources().getDimensionPixelSize(R.dimen.dd_debug_drawer_margin));
            }
        }

        if (drawerWidth > -1) {
            params.width = drawerWidth;
        } else {
            params.width = UIUtils.getOptimalDrawerWidth(activity);
        }
    }

    return params;
}
 
Example 7
Source Project: ProgressStatusBar   Source File: ProgressStatusBar.java    License: Apache License 2.0 6 votes vote down vote up
private void init() {

        int barColor = Color.parseColor("#60ffffff");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            barColor = Color.parseColor("#40212121");
        }

        progressPaint = new Paint();
        progressPaint.setStyle(Paint.Style.FILL);
        progressPaint.setColor(barColor);

        windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);

        params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.MATCH_PARENT, getStatusBarHeight(getContext()),
                WindowManager.LayoutParams.FIRST_SUB_WINDOW,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                        | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                        | WindowManager.LayoutParams.FLAG_FULLSCREEN
                        | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
                PixelFormat.TRANSLUCENT);
        params.gravity = Gravity.TOP | Gravity.LEFT;
        
        setBackgroundColor(Color.TRANSPARENT);
        
    }
 
Example 8
Source Project: zulip-android   Source File: UnsortedTests.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Run this before each test to set up the activity.
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void prepTests() {
    setApplication(app);
    this.startActivity(new Intent(getInstrumentation().getTargetContext(),
            ZulipActivity.class), null, null);
    this.getInstrumentation().waitForIdleSync();
    app.setContext(getInstrumentation().getTargetContext());
    // Need to setEmail twice to reinitialise the database after destroying
    // it.
    app.setEmail(TESTUSER_EXAMPLE_COM);
    app.deleteDatabase(app.getDatabaseHelper().getDatabaseName());
    app.setEmail(TESTUSER_EXAMPLE_COM);
    messageDao = app.getDao(Message.class);

}
 
Example 9
Source Project: LiveMultimedia   Source File: LollipopCamera.java    License: Apache License 2.0 6 votes vote down vote up
/*********************************************************
 * Close the camera.
 ********************************************************/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void closeCamera() {
    try {
        mCameraOpenCloseLock.acquire();
        if (null != mCameraDevice) {
            mCameraDevice.close();
            mCameraDevice = null;
        }
        if (null != mMediaRecorder) {
            mMediaRecorder.release();
            mMediaRecorder = null;
        }
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted while trying to lock camera closing.");
    } finally {
        mCameraOpenCloseLock.release();
    }
}
 
Example 10
Source Project: PermissionGen   Source File: PermissionGen.java    License: Apache License 2.0 6 votes vote down vote up
@TargetApi(value = Build.VERSION_CODES.M)
private static void requestPermissions(Object object, int requestCode, String[] permissions){
  if(!Utils.isOverMarshmallow()) {
    doExecuteSuccess(object, requestCode);
    return;
  }
  List<String> deniedPermissions = Utils.findDeniedPermissions(getActivity(object), permissions);

  if(deniedPermissions.size() > 0){
    if(object instanceof Activity){
      ((Activity)object).requestPermissions(deniedPermissions.toArray(new String[deniedPermissions.size()]), requestCode);
    } else if(object instanceof Fragment){
      ((Fragment)object).requestPermissions(deniedPermissions.toArray(new String[deniedPermissions.size()]), requestCode);
    } else {
      throw new IllegalArgumentException(object.getClass().getName() + " is not supported");
    }

  } else {
    doExecuteSuccess(object, requestCode);
  }
}
 
Example 11
Source Project: PlayerBase   Source File: ShareAnimationActivityA.java    License: Apache License 2.0 6 votes vote down vote up
@OnClick({R.id.album_layout, R.id.tv_title})
public void onViewClicked(View view) {
    ShareAnimationPlayer.get().setReceiverGroup(mReceiverGroup);
    switch (view.getId()) {
        case R.id.album_layout:
            playIcon.setVisibility(View.GONE);
            ShareAnimationPlayer.get().play(mLayoutContainer, mData);
            break;
        case R.id.tv_title:
            toNext = true;
            Intent intent = new Intent(this, ShareAnimationActivityB.class);
            intent.putExtra(ShareAnimationActivityB.KEY_DATA, mData);
            if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP){
                ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(
                        this, mLayoutContainer, "videoShare");
                ActivityCompat.startActivity(this, intent, options.toBundle());
            }else{
                startActivity(intent);
            }
            break;
    }
}
 
Example 12
Source Project: delion   Source File: PwsClientImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Recreate the Chrome for Android User-Agent string as closely as possible without calling any
 * native code.
 * @return A User-Agent string
 */
@VisibleForTesting
String getUserAgent() {
    if (sUserAgent == null) {
        // Build the OS info string.
        // eg: Linux; Android 5.1.1; Nexus 4 Build/LMY48T
        String osInfo = String.format(OS_INFO_FORMAT, Build.VERSION.RELEASE, Build.MODEL,
                Build.ID);

        // Build the product string.
        // eg: Chrome/50.0.2661.89 Mobile
        String product = String.format(PRODUCT_FORMAT, ChromeVersionInfo.getProductVersion());

        // Build the User-Agent string.
        // eg: Mozilla/5.0 (Linux; Android 5.1.1; Nexus 4 Build/LMY48T) AppleWebKit/0.0 (KHTML,
        //     like Gecko) Chrome/50.0.2661.89 Mobile Safari/0.0
        sUserAgent = String.format(USER_AGENT_FORMAT, osInfo, product);
    }
    return sUserAgent;
}
 
Example 13
Source Project: quickmark   Source File: InPtypeManager.java    License: MIT License 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	requestWindowFeature(Window.FEATURE_NO_TITLE);
	setContentView(R.layout.inptypemanager);

	SystemBarTintManager mTintManager;
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
		findViewById(R.id.inptext_top).setVisibility(View.VISIBLE);
		setTranslucentStatus(true);
	}
	mTintManager = new SystemBarTintManager(this);
	mTintManager.setStatusBarTintEnabled(true);
	mTintManager.setStatusBarTintResource(R.color.statusbar_bg);

	SysApplication.getInstance().addActivity(this); // �����ٶ��������this
	inptext = (TextView) findViewById(R.id.inptext);
	lv = (ListView) findViewById(R.id.typelist);// �õ�ListView���������
	add = (Button) findViewById(R.id.addtype);
	delete = (Button) findViewById(R.id.deletetype);
}
 
Example 14
Source Project: Recovery   Source File: ActivityStackCompat.java    License: Apache License 2.0 6 votes vote down vote up
public static String getBaseActivityName(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ActivityManager.AppTask appTask = getTopTaskAfterL(context);
        if (appTask == null)
            return null;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            return appTask.getTaskInfo().baseActivity.getClassName();
        } else {
            ComponentName componentName = RecoveryStore.getInstance().getBaseActivity();
            return componentName == null ? null : componentName.getClassName();
        }
    } else {
        ActivityManager.RunningTaskInfo taskInfo = getTopTaskBeforeL(context);
        if (taskInfo == null)
            return null;
        return taskInfo.baseActivity.getClassName();
    }
}
 
Example 15
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
  mode.getMenuInflater().inflate(R.menu.profile_context, menu);
  mode.setTitle("1");

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    Window window = getActivity().getWindow();
    originalStatusBarColor = window.getStatusBarColor();
    window.setStatusBarColor(getResources().getColor(R.color.action_mode_status_bar));
  }
  return true;
}
 
Example 16
Source Project: o2oa   Source File: FileUtils.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * sd卡容量
 *
 * @return
 */
public static long getAvailableStorage() {
    long availableSize = 0;
    if (isSDCardExist()) {
        File sdFile = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(sdFile.getPath());
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR2) {
            availableSize = stat.getAvailableBytes();
        } else {
            availableSize = ((long) stat.getAvailableBlocks() * stat.getBlockSize());
        }
    }
    return availableSize;
}
 
Example 17
Source Project: FloatingModMenu   Source File: MainActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void Start() {
    System.loadLibrary("KittyMemory");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) {
        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
        startActivityForResult(intent, CODE_DRAW_OVER_OTHER_APP_PERMISSION);
    } else {
        startService(new Intent(MainActivity.this, FloatingModMenuService.class));
    }
}
 
Example 18
public static boolean hasEnrolledFingerprints(@NonNull Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        final FingerprintManager manager = context.getSystemService(FingerprintManager.class);
        return manager != null && manager.hasEnrolledFingerprints();
    } else {
        Log.e(TAG, "Device software version is too low so we return " +
                "hasEnrolledFingerprints=false instead. Recommend to check software version " +
                "by yourself before using BiometricPromptCompat.");
        return false;
    }
}
 
Example 19
Source Project: styT   Source File: ActivityResourceFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Drawable getDrawable(@DrawableRes int resId)
{
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
    {
        return mActivity.getDrawable(resId);
    }
    else
    {
        //noinspection deprecation
        return mActivity.getResources().getDrawable(resId);
    }
}
 
Example 20
Source Project: OkDeepLink   Source File: RealCall.java    License: Apache License 2.0 5 votes vote down vote up
private Context getStartContext(Context context) {
    if (context instanceof Activity) {
        Activity activity = (Activity) context;
        boolean isDestroyed = false;
        if (activity.isFinishing()) {
            isDestroyed = true;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            if (activity.isDestroyed()) {
                isDestroyed = true;
            }

        }
        FragmentManager fragmentManager = activity.getFragmentManager();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            if (fragmentManager.isDestroyed()) {
                isDestroyed = true;
            }
        }
        if (context instanceof FragmentActivity) {
            FragmentActivity fragmentActivity = (FragmentActivity) context;
            android.support.v4.app.FragmentManager fragmentManagerV4 = fragmentActivity.getSupportFragmentManager();

            if (fragmentManagerV4.isDestroyed()) {
                isDestroyed = true;
            }
        }
        if (isDestroyed) {
            return context.getApplicationContext();
        }
    }
    return context;
}
 
Example 21
/**
 * Start animation.
 */
public void startAnimation() {
       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && valueAnimator.isPaused()) {
           valueAnimator.resume();
           return;
       }
       if (valueAnimator.isRunning())
           return;
       valueAnimator.start();
}
 
Example 22
Source Project: leafpicrevived   Source File: StorageHelper.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Delete a folder.
 *
 * @param file The folder name.
 * @return true if successful.
 */
public static boolean rmdir(Context context, @NonNull final File file) {

    if (!file.exists() && !file.isDirectory()) return false;

    String[] fileList = file.list();

    if (fileList != null && fileList.length > 0)
        // Delete only empty folder.
        return false;

    // Try the normal way
    if (file.delete()) return true;


    // Try with Storage Access Framework.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        DocumentFile document = getDocumentFile(context, file, true, true);
        return document != null && document.delete();
    }

    // Try the Kitkat workaround.
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
        ContentResolver resolver = context.getContentResolver();
        ContentValues values = new ContentValues();
        values.put(MediaStore.MediaColumns.DATA, file.getAbsolutePath());
        resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

        // Delete the created entry, such that content provider will delete the file.
        resolver.delete(MediaStore.Files.getContentUri("external"), MediaStore.MediaColumns.DATA + "=?",
                new String[]{file.getAbsolutePath()});
    }

    return !file.exists();
}
 
Example 23
public View initWidget(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {

        View contextView = inflater.inflate(R.layout.item_imageslooker_photoview, container, false);

//        setContentView(R.layout.activity_imagelooker_main);

        mPhotoView = (PhotoView) contextView.findViewById(R.id.photoview);
        gifImageView = (GifView) contextView.findViewById(R.id.gifImageView);
//        mPhotoView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        mPhotoView.setBackgroundColor(0);
        // The MAGIC happens here!
//        mAttacher = new PhotoViewAttacher(mPhotoView);

        // Lets attach some listeners, not required though!
//        mAttacher.setOnMatrixChangeListener(new MatrixChangeListener());
//        mAttacher.setOnPhotoTapListener(new PhotoTapListener());
//        mAttacher.setAdapterWidth(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            mPhotoView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        }

        rpb = (RoundProgressBar) contextView.findViewById(R.id.pb);

//        LogUtils.printLog(ImagesLookerPhotoViewFragment.class, "rpb:" + rpb);
//        Drawable bitmap = getResources().getDrawable(R.drawable.default_pic);
//        mPhotoView.setImageDrawable(bitmap);

        // The MAGIC happens here!


//        mAttacher.setScale(1f, 0, 0, true);

        imageView = mPhotoView;
        return contextView;
    }
 
Example 24
Source Project: hipda   Source File: EmojiPopup.java    License: GNU General Public License v2.0 5 votes vote down vote up
private int getUsableScreenHeight() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        final DisplayMetrics metrics = new DisplayMetrics();

        final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        windowManager.getDefaultDisplay().getMetrics(metrics);

        return metrics.heightPixels;

    } else {
        return rootView.getRootView().getHeight();
    }
}
 
Example 25
Source Project: Kalle   Source File: Headers.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get User-Agent.
 */
public static String getUserAgent() {
    String webUserAgent = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/534.30 (KHTML, like Gecko) Version/5.0 %sSafari/534.30";

    StringBuffer buffer = new StringBuffer();
    buffer.append(Build.VERSION.RELEASE).append("; ");

    Locale locale = Locale.getDefault();
    String language = locale.getLanguage();
    if (TextUtils.isEmpty(language)) {
        buffer.append(language.toLowerCase(locale));
        final String country = locale.getCountry();
        if (!TextUtils.isEmpty(country)) {
            buffer.append("-");
            buffer.append(country.toLowerCase(locale));
        }
    } else {
        buffer.append("en");
    }
    if ("REL".equals(Build.VERSION.CODENAME)) {
        if (Build.MODEL.length() > 0) {
            buffer.append("; ");
            buffer.append(Build.MODEL);
        }
    }
    if (Build.ID.length() > 0) {
        buffer.append(" Api/");
        buffer.append(Build.ID);
    }
    return String.format(webUserAgent, buffer, "Mobile ");
}
 
Example 26
Source Project: commcare-android   Source File: NdefRecordUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static NdefRecord createTextRecord(String payload) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return NdefRecord.createTextRecord(null, payload);
    } else {
        return createTextRecordManually(payload, Locale.getDefault());
    }
}
 
Example 27
Source Project: ultimate-cordova-webview-app   Source File: SystemCookieManager.java    License: MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public SystemCookieManager(WebView webview) {
    webView = webview;
    cookieManager = CookieManager.getInstance();

    //REALLY? Nobody has seen this UNTIL NOW?
    cookieManager.setAcceptFileSchemeCookies(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        cookieManager.setAcceptThirdPartyCookies(webView, true);
    }
}
 
Example 28
Source Project: Telegram   Source File: ContactsActivity.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    if (listViewAdapter != null) {
        listViewAdapter.notifyDataSetChanged();
    }
    if (checkPermission && Build.VERSION.SDK_INT >= 23) {
        Activity activity = getParentActivity();
        if (activity != null) {
            checkPermission = false;
            if (activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
                if (activity.shouldShowRequestPermissionRationale(Manifest.permission.READ_CONTACTS)) {
                    AlertDialog.Builder builder = AlertsCreator.createContactsPermissionDialog(activity, param -> {
                        askAboutContacts = param != 0;
                        if (param == 0) {
                            return;
                        }
                        askForPermissons(false);
                    });
                    showDialog(permissionDialog = builder.create());
                } else {
                    askForPermissons(true);
                }
            }
        }
    }
}
 
Example 29
Source Project: PermissionAgent   Source File: XiaomiPageLauncherFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PageLauncher createOverlayLauncher() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M
            && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        return new KXiaomiOverlayPageLauncher();
    }
    return null;
}
 
Example 30
Source Project: android-mvvm-with-tests   Source File: MatcherEx.java    License: MIT License 5 votes vote down vote up
/**
 * Returns a matcher that matches {@link View}s has listener
 */
public static Matcher<View> hasListener() {
    return new TypeSafeMatcher<View>() {
        @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
        @Override
        protected boolean matchesSafely(View view) {
            return view.hasOnClickListeners();
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("has onclick listener");
        }
    };
}