public void setTranslucentBackgroundDrawable(@Nullable Drawable background) {
   // it's required to call setBackground to null, as in some of the cases we may set new
   // background to be a layer drawable that contains a drawable that has been previously setup
   // as a background previously. This will not work correctly as the drawable callback logic is
   // messed up in AOSP
   super.setBackground(null);
   if (mReactBackgroundDrawable != null && background != null) {
     LayerDrawable layerDrawable =
         new LayerDrawable(new Drawable[] {mReactBackgroundDrawable, background});
     super.setBackground(layerDrawable);
   } else if (background != null) {
     super.setBackground(background);
   }
 }
 private ReactViewBackgroundDrawable getOrCreateReactViewBackground() {
   if (mReactBackgroundDrawable == null) {
     mReactBackgroundDrawable = new ReactViewBackgroundDrawable();
     Drawable backgroundDrawable = getBackground();
     super.setBackground(null); // required so that drawable callback is cleared before we add the
     // drawable back as a part of LayerDrawable
     if (backgroundDrawable == null) {
       super.setBackground(mReactBackgroundDrawable);
     } else {
       LayerDrawable layerDrawable =
           new LayerDrawable(new Drawable[] {mReactBackgroundDrawable, backgroundDrawable});
       super.setBackground(layerDrawable);
     }
   }
   return mReactBackgroundDrawable;
 }
Esempio n. 3
0
  // 设置全局图片并且沉浸
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  private void setFull(
      Activity activity, int backRes, int headColor, float scale, float startBlur, float endBlur) {
    Bitmap backBitmap = BitmapFactory.decodeResource(getResources(), backRes);
    int color = getResources().getColor(headColor);
    if (backBitmap != null) { // 图片背景
      statusView = setColor(activity, Color.TRANSPARENT); // 设置透明状态栏
      statusView.setBackgroundColor(color); // 设置内容区域状态栏颜色
      isTranslate = true;
      ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
      Drawable backDrawable = null;
      if (startBlur == 0 && endBlur == 0) { // 正常背景
        backDrawable = new BitmapDrawable(backBitmap);
      } else { // 模糊背景
        if (endBlur == 0) {
          backDrawable = new BitmapDrawable(backBitmap);
        } else {
          backDrawable =
              new BitmapDrawable(BlurUtil.fastblur(getContext(), backBitmap, scale, endBlur));
        }
      }
      if (startBlur != endBlur) { // 动态模糊
        mBackImageView = new ImageView(activity);
        mBackImageView.setLayoutParams(new LayoutParams(mScreenWidth, mScreenHeight));
        mBackImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        if (startBlur == 0) {
          mBackImageView.setImageBitmap(backBitmap);
        } else {
          mBackImageView.setImageBitmap(
              BlurUtil.fastblur(getContext(), backBitmap, scale, startBlur));
        }
        decorView.addView(mBackImageView, 0);
      }
      decorView.setBackground(backDrawable);

    } else { // 颜色背景
      isTranslate = false;
      setBackgroundColor(color); // 设置背景
      statusView = setColor(activity, color); // 设置状态栏颜色
    } // 解决内容区域页面上移问题
    if (!isTranslated) {
      mContentView = getChildAt(1);
      LinearLayout ll = new LinearLayout(activity);
      ll.setLayoutParams(new LinearLayout.LayoutParams(mScreenWidth, mScreenHeight));
      ll.setOrientation(LinearLayout.VERTICAL);
      ll.setBackgroundColor(Color.WHITE);
      removeViewAt(1);
      ll.addView(createStatusBarView(activity, Color.TRANSPARENT)); // 填充空白界面
      ll.addView(mContentView);
      addView(ll);
      isTranslated = true;
    }
  }
Esempio n. 4
0
  public void showLongPressCling(boolean showWelcome) {
    ViewGroup root = (ViewGroup) mLauncher.findViewById(R.id.launcher);
    View cling = mInflater.inflate(R.layout.longpress_cling, root, false);

    cling.setOnLongClickListener(
        new OnLongClickListener() {

          @Override
          public boolean onLongClick(View v) {
            mLauncher.getWorkspace().enterOverviewMode();
            dismissLongPressCling();
            return true;
          }
        });

    final ViewGroup content = (ViewGroup) cling.findViewById(R.id.cling_content);
    mInflater.inflate(
        showWelcome ? R.layout.longpress_cling_welcome_content : R.layout.longpress_cling_content,
        content);
    content.findViewById(R.id.cling_dismiss_longpress_info).setOnClickListener(this);

    if (TAG_CROP_TOP_AND_SIDES.equals(content.getTag())) {
      Drawable bg =
          new BorderCropDrawable(
              mLauncher.getResources().getDrawable(R.drawable.cling_bg), true, true, true, false);
      content.setBackground(bg);
    }

    root.addView(cling);

    if (showWelcome) {
      // This is the first cling being shown. No need to animate.
      return;
    }

    // Animate
    content
        .getViewTreeObserver()
        .addOnGlobalLayoutListener(
            new OnGlobalLayoutListener() {

              @Override
              public void onGlobalLayout() {
                content.getViewTreeObserver().removeOnGlobalLayoutListener(this);

                ObjectAnimator anim;
                if (TAG_CROP_TOP_AND_SIDES.equals(content.getTag())) {
                  content.setTranslationY(-content.getMeasuredHeight());
                  anim = LauncherAnimUtils.ofFloat(content, "translationY", 0);
                } else {
                  content.setScaleX(0);
                  content.setScaleY(0);
                  PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1);
                  PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1);
                  anim = LauncherAnimUtils.ofPropertyValuesHolder(content, scaleX, scaleY);
                }

                anim.setDuration(SHOW_CLING_DURATION);
                anim.setInterpolator(new LogDecelerateInterpolator(100, 0));
                anim.start();
              }
            });
  }
Esempio n. 5
0
  @SuppressWarnings("deprecation")
  @SuppressLint("NewApi")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main_activity, R.layout.main_titlebar_layout);

    if (!isAddShortCut()) {
      addShortCut();
    }

    ImageView settings = (ImageView) findViewById(R.id.settings_img);
    settings.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, SettingsActivity.class));
          }
        });

    mBackground = new MyColorBackground();

    mViewPager = (ViewPager) findViewById(R.id.main_viewpager);
    mViewList = new ArrayList<MainView>();
    MainView view = new CountMainView(this);
    mViewList.add(view);
    view = new TimeMainView(this);
    mViewList.add(view);
    MainPagerAdapter pagerAdapter = new MainPagerAdapter(mViewList);
    mViewPager.setAdapter(pagerAdapter);
    mViewPager.setOnPageChangeListener(this);

    LinearLayout layoutRoot = (LinearLayout) findViewById(R.id.main_layout_root);
    layoutRoot.setBackground(mBackground);

    mRadioGroup = (RadioGroup) findViewById(R.id.pagerRadioGroup);
    mRadioGroup.setOnCheckedChangeListener(
        new OnCheckedChangeListener() {

          @Override
          public void onCheckedChanged(RadioGroup group, int checkedId) {
            int count = group.getChildCount();
            for (int index = 0; index < count; index++) {
              RadioButton btn = (RadioButton) group.getChildAt(index);
              if (btn.getId() == checkedId) {
                if (mViewPager.getCurrentItem() != index) {
                  mViewPager.setCurrentItem(index, true);
                }
              }
            }
          }
        });

    mListView = (ExpandableListView) findViewById(R.id.unlock_detail_list);
    mListView.setGroupIndicator(null);
    mAdapters = new DetailListAdapter[2];
    mAdapters[0] = new UnlockDetailListAdapter(this);
    mAdapters[1] = new TimeDetailListAdapter(this);
    mListView.setDivider(null);
    mListView.setChildDivider(null);
    mListBackground = new MyColorBackground();
    mListView.setBackground(mListBackground);

    slidingDrawer = (SlidingDrawer) findViewById(R.id.sliding_detail);
    final ImageView arrow = (ImageView) findViewById(R.id.sliding_handle_arrow);
    final TextView handleText = (TextView) findViewById(R.id.sliding_handle_text);
    final ViewGroup slidingHandle = (ViewGroup) findViewById(R.id.sliding_handle);
    slidingDrawable = new SingleColorDrawable(1, true);
    slidingHandle.setBackground(slidingDrawable);

    slidingDrawer.setOnDrawerOpenListener(
        new OnDrawerOpenListener() {

          @Override
          public void onDrawerOpened() {
            handleText.setVisibility(View.GONE);
            arrow.setImageResource(R.drawable.down_arrow);
            mAdapters[mViewPager.getCurrentItem()].refreshData();
            mAdapters[mViewPager.getCurrentItem()].notifyDataSetChanged();
            int n = mListView.getCount();
            for (int i = 0; i < n; i++) {
              mListView.expandGroup(i);
            }
          }
        });

    slidingDrawer.setOnDrawerCloseListener(
        new OnDrawerCloseListener() {

          @Override
          public void onDrawerClosed() {
            handleText.setVisibility(View.VISIBLE);
            arrow.setImageResource(R.drawable.up_arrow);
          }
        });

    setMainTitle(R.string.main_title);

    View title_layout = (View) findViewById(R.id.titlebar_layout_root);
    SingleColorDrawable back = new SingleColorDrawable(0, false);
    title_layout.setBackground(back);
    IncrementAnimationUtil.getInstance().addObserver(back);
    IncrementAnimationUtil.getInstance().addObserver(mBackground);
    IncrementAnimationUtil.getInstance().addObserver(mListBackground);
    IncrementAnimationUtil.getInstance().addObserver(slidingDrawable);
  }