Ejemplo n.º 1
0
  private void configureToolbarView() {
    setSupportActionBar(mToolbarView);
    mToolbarView.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
    mToolbarView.setNavigationOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            EventActivity.this.onBackPressed();
          }
        });

    // Remove toolbars title, as we have our own title implementation
    mToolbarView.post(
        new Runnable() {
          @Override
          public void run() {
            mToolbarView.setTitle("");
          }
        });

    mToolbarBackgroundColor = getResources().getColor(R.color.colorPrimary);
    TypedValue tv = new TypedValue();
    if (EventActivity.this.getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
      mToolbarHeight =
          TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
    }
    setBackgroundAlpha(mToolbarView, 0.0f, mToolbarBackgroundColor);
  }
Ejemplo n.º 2
0
  public GameCanvas(DrawPanel g) {
    // set height and width
    Display mDisplay = g.ctx.getWindowManager().getDefaultDisplay();
    width = mDisplay.getWidth();
    height = mDisplay.getHeight();
    numbers = g.ctx.sharedPrefs.getInt("numbers", 0);

    TypedValue tv = new TypedValue();
    if (g.ctx.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
      actionBarHeight =
          TypedValue.complexToDimensionPixelSize(tv.data, g.ctx.getResources().getDisplayMetrics());
    }

    final LinearLayout ll = (LinearLayout) g.ctx.findViewById(R.id.fullscreen_content_controls);
    ll.post(
        new Runnable() {
          public void run() {
            navBarHeight = ll.getHeight();
            //		 		Log.v("THINGS", ""+actionBarHeight+" "+navBarHeight+" "+statusBarHeight);

          }
        });

    int resourceId = g.ctx.getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
      statusBarHeight = g.ctx.getResources().getDimensionPixelSize(resourceId);
    }

    mpaint = new Paint();
    mpaint.setTextSize(text_size);
    g.sensitivity = height / 10;
    dv = g;
    grid = new GridLock(dv.size, dv.size, this);
  }
Ejemplo n.º 3
0
 /**
  * 获取ActionBar高度
  *
  * @param activity activity
  * @return ActionBar高度
  */
 public static int getActionBarHeight(Activity activity) {
   TypedValue tv = new TypedValue();
   if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
     return TypedValue.complexToDimensionPixelSize(
         tv.data, activity.getResources().getDisplayMetrics());
   }
   return 0;
 }
Ejemplo n.º 4
0
 public int getActionBarHeight() {
   int actionBarHeight = 0;
   TypedValue tv = new TypedValue();
   if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
     actionBarHeight =
         TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
   }
   return actionBarHeight;
 }
Ejemplo n.º 5
0
  public static int getActionBarHeight(Context context) {
    TypedValue v = new TypedValue();

    if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, v, true)) {
      return TypedValue.complexToDimensionPixelSize(
          v.data, context.getResources().getDisplayMetrics());
    } else {
      return 0;
    }
  }
Ejemplo n.º 6
0
 public static int getActionBarSize(Context context) {
   if (actionBarSize < 0) {
     TypedValue value = new TypedValue();
     context.getTheme().resolveAttribute(android.R.attr.actionBarSize, value, true);
     actionBarSize =
         TypedValue.complexToDimensionPixelSize(
             value.data, context.getResources().getDisplayMetrics());
   }
   return actionBarSize;
 }
  public static int getActionBarHeight(Context context) {
    if (sActionBarHeight != 0) {
      return sActionBarHeight;
    }

    context.getTheme().resolveAttribute(android.R.attr.actionBarSize, sTypedValue, true);
    sActionBarHeight =
        TypedValue.complexToDimensionPixelSize(
            sTypedValue.data, context.getResources().getDisplayMetrics());
    return sActionBarHeight;
  }
 @TargetApi(14)
 private int getActionBarHeight(Context context) {
   int result = 0;
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
     TypedValue tv = new TypedValue();
     context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
     result =
         TypedValue.complexToDimensionPixelSize(
             tv.data, context.getResources().getDisplayMetrics());
   }
   return result;
 }
Ejemplo n.º 9
0
  /**
   * Special version of {@link #getDimensionPixelSize} for retrieving {@link
   * android.view.ViewGroup}'s layout_width and layout_height attributes. This is only here for
   * performance reasons; applications should use {@link #getDimensionPixelSize}.
   *
   * @param index Index of the attribute to retrieve.
   * @param defValue The default value to return if this attribute is not default or contains the
   *     wrong type of data.
   * @return Attribute dimension value multiplied by the appropriate metric and truncated to integer
   *     pixels.
   */
  public int getLayoutDimension(int index, int defValue) {
    index *= AssetManager.STYLE_NUM_ENTRIES;
    final int[] data = mData;
    final int type = data[index + AssetManager.STYLE_TYPE];
    if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
      return data[index + AssetManager.STYLE_DATA];
    } else if (type == TypedValue.TYPE_DIMENSION) {
      return TypedValue.complexToDimensionPixelSize(
          data[index + AssetManager.STYLE_DATA], mResources.mMetrics);
    }

    return defValue;
  }
Ejemplo n.º 10
0
  /**
   * Special version of {@link #getDimensionPixelSize} for retrieving {@link
   * android.view.ViewGroup}'s layout_width and layout_height attributes. This is only here for
   * performance reasons; applications should use {@link #getDimensionPixelSize}.
   *
   * @param index Index of the attribute to retrieve.
   * @param name Textual name of attribute for error reporting.
   * @return Attribute dimension value multiplied by the appropriate metric and truncated to integer
   *     pixels.
   */
  public int getLayoutDimension(int index, String name) {
    index *= AssetManager.STYLE_NUM_ENTRIES;
    final int[] data = mData;
    final int type = data[index + AssetManager.STYLE_TYPE];
    if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
      return data[index + AssetManager.STYLE_DATA];
    } else if (type == TypedValue.TYPE_DIMENSION) {
      return TypedValue.complexToDimensionPixelSize(
          data[index + AssetManager.STYLE_DATA], mResources.mMetrics);
    }

    throw new RuntimeException(
        getPositionDescription() + ": You must supply a " + name + " attribute.");
  }
Ejemplo n.º 11
0
  /**
   * Retrieve a dimensional unit attribute at <var>index</var> for use as a size in raw pixels. This
   * is the same as {@link #getDimension}, except the returned value is converted to integer pixels
   * for use as a size. A size conversion involves rounding the base value, and ensuring that a
   * non-zero base value is at least one pixel in size.
   *
   * @param index Index of attribute to retrieve.
   * @param defValue Value to return if the attribute is not defined or not a resource.
   * @return Attribute dimension value multiplied by the appropriate metric and truncated to integer
   *     pixels, or defValue if not defined.
   * @see #getDimension
   * @see #getDimensionPixelOffset
   */
  public int getDimensionPixelSize(int index, int defValue) {
    index *= AssetManager.STYLE_NUM_ENTRIES;
    final int[] data = mData;
    final int type = data[index + AssetManager.STYLE_TYPE];
    if (type == TypedValue.TYPE_NULL) {
      return defValue;
    } else if (type == TypedValue.TYPE_DIMENSION) {
      return TypedValue.complexToDimensionPixelSize(
          data[index + AssetManager.STYLE_DATA], mResources.mMetrics);
    }

    throw new UnsupportedOperationException(
        "Can't convert to dimension: type=0x" + Integer.toHexString(type));
  }
  @Override
  public int getDimensionPixelSize(int id) throws NotFoundException {
    IResourceValue value = getResourceValue(id, mPlatformResourceFlag);

    if (value != null) {
      String v = value.getValue();

      if (v != null) {
        if (ResourceHelper.stringToFloat(v, mTmpValue)
            && mTmpValue.type == TypedValue.TYPE_DIMENSION) {
          return TypedValue.complexToDimensionPixelSize(mTmpValue.data, mMetrics);
        }
      }
    }

    // id was not found or not resolved. Throw a NotFoundException.
    throwException(id);

    // this is not used since the method above always throws
    return 0;
  }
Ejemplo n.º 13
0
  public void applyLollipopActionBar() {
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {

      // Calculate ActionBar and navigation bar height.
      TypedValue tv = new TypedValue();
      int actionBarHeight = 0;
      if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        actionBarHeight =
            TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
      }

      ((View) this.getListView().getParent())
          .setPadding(0, actionBarHeight + mApp.getStatusBarHeight(mContext), 0, 0);

      this.getListView().setBackgroundColor(0xFFEEEEEE);
      this.getListView().setPadding(0, 0, 0, mApp.getNavigationBarHeight(mContext));
      this.getListView().setClipToPadding(false);

      // Set the window color.
      getWindow().setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext));
    }
  }
  /** Applies KitKat specific translucency. */
  private void applyKitKatTranslucency() {
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {

      // Calculate ActionBar and navigation bar height.
      TypedValue tv = new TypedValue();
      int actionBarHeight = 0;
      if (getActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        actionBarHeight =
            TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
      }

      mListView.setBackgroundColor(0xFFEEEEEE);
      mRootView.setPadding(0, actionBarHeight + mApp.getStatusBarHeight(mContext), 0, 0);
      mListView.setPadding(10, 0, 10, mApp.getNavigationBarHeight(mContext));
      mListView.setClipToPadding(false);

      // Set the window color.
      getActivity()
          .getWindow()
          .setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext));
    }
  }
  ActionMode startSupportActionModeFromWindow(ActionMode.Callback callback) {
    if (mActionMode != null) {
      mActionMode.finish();
    }

    final ActionMode.Callback wrappedCallback = new ActionModeCallbackWrapper(callback);

    if (mActionModeView == null) {
      // Use the action bar theme.
      final Context actionBarContext;
      actionBarContext =
          ThemeUtils.getActionBarThemedContext(
              mActivity, mThemed.getCurrentThemeResourceId(), mThemed.getCurrentThemeColor());

      mActionModeView = new ActionBarContextView(actionBarContext);
      mActionModePopup =
          new PopupWindow(
              actionBarContext,
              null,
              android.support.v7.appcompat.R.attr.actionModePopupWindowStyle);
      mActionModePopup.setContentView(mActionModeView);

      final TypedValue outValue = new TypedValue();
      actionBarContext
          .getTheme()
          .resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, outValue, true);
      final int height =
          TypedValue.complexToDimensionPixelSize(
              outValue.data, actionBarContext.getResources().getDisplayMetrics());
      mActionModeView.setContentHeight(height);
      ThemeUtils.setActionBarContextViewBackground(
          mActionModeView,
          mThemed.getCurrentThemeResourceId(),
          mThemed.getCurrentThemeColor(),
          mThemed.getCurrentThemeBackgroundOption(),
          false);
      mActionModePopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
      final Rect actionModeBounds = getActionModeBounds();
      if (actionModeBounds != null) {
        mActionModePopup.setWidth(actionModeBounds.width());
      } else {
        mActionModePopup.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
      }
      mShowActionModePopup =
          new Runnable() {
            @Override
            public void run() {
              if (actionModeBounds != null) {
                mActionModePopup.showAtLocation(
                    mWindow.getDecorView(),
                    Gravity.TOP | Gravity.LEFT,
                    actionModeBounds.left,
                    actionModeBounds.top);
              } else {
                mActionModePopup.showAtLocation(
                    mWindow.getDecorView(), Gravity.TOP | Gravity.LEFT, 0, 0);
              }
            }
          };
    }

    if (mActionModeView != null) {
      mActionModeView.killMode();
      ActionMode mode =
          new StandaloneActionMode(
              mActionModeView.getContext(),
              mActionModeView,
              wrappedCallback,
              mActionModePopup == null);
      if (callback.onCreateActionMode(mode, mode.getMenu())) {
        mode.invalidate();
        mActionModeView.initForMode(mode);
        mActionModeView.setVisibility(View.VISIBLE);
        mActionMode = mode;
        if (mActionModePopup != null) {
          mWindow.getDecorView().post(mShowActionModePopup);
        }
        mActionModeView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);

        if (mActionModeView.getParent() != null) {
          ViewCompat.requestApplyInsets((View) mActionModeView.getParent());
        }
      } else {
        mActionMode = null;
      }
    }
    if (mActionMode != null && mAppCompatCallback != null) {
      mAppCompatCallback.onSupportActionModeStarted(mActionMode);
    }
    return mActionMode;
  }
  @SuppressWarnings("unchecked")
  @Override
  public void onCreate(Bundle savedInstanceState) {

    // Initialize Context and SharedPreferences.
    mContext = this;
    mApp = (Common) mContext.getApplicationContext();

    // Retrieve the name/icon of the library from the arguments.
    libraryName = getIntent().getExtras().getString("LIBRARY_NAME");
    libraryIconName = getIntent().getExtras().getString("LIBRARY_ICON");

    if (getIntent().getExtras().getSerializable("SONG_IDS_HASH_SET") != null) {
      songDBIdsList =
          (HashSet<String>) getIntent().getExtras().getSerializable("SONG_IDS_HASH_SET");
    }

    // Set the UI theme.
    if (mApp.getCurrentTheme() == Common.DARK_THEME) {
      setTheme(R.style.AppTheme);
    } else {
      setTheme(R.style.AppThemeLight);
    }
    super.onCreate(savedInstanceState);

    // Initialize the database helper.
    dbHelper = new DBAccessHelper(mContext.getApplicationContext());

    // Create a set of options to optimize the bitmap memory usage.
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    options.inJustDecodeBounds = false;
    options.inPurgeable = true;

    // Display Image Options.
    int defaultArt = UIElementsHelper.getIcon(mContext, "default_album_art_padded");
    displayImageOptions =
        new DisplayImageOptions.Builder()
            .showImageForEmptyUri(R.drawable.default_album_art)
            .showImageOnFail(R.drawable.default_album_art)
            .showStubImage(R.drawable.transparent_drawable)
            .cacheInMemory(false)
            .cacheOnDisc(true)
            .decodingOptions(options)
            .imageScaleType(ImageScaleType.EXACTLY)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .displayer(new FadeInBitmapDisplayer(400))
            .delayBeforeLoading(100)
            .build();

    // Attach tabs to the ActionBar.
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Add the artists tab.
    String artistsLabel = getResources().getString(R.string.artists);
    Tab tab = actionBar.newTab();
    tab.setText(artistsLabel);
    TabListener<ArtistsPickerFragment> artistsTabListener =
        new TabListener<ArtistsPickerFragment>(this, artistsLabel, ArtistsPickerFragment.class);

    tab.setTabListener(artistsTabListener);
    actionBar.addTab(tab);

    // Add the albums tab.
    String albumsLabel = getResources().getString(R.string.albums);
    tab = actionBar.newTab();
    tab.setText(albumsLabel);
    TabListener<AlbumsPickerFragment> albumsTabListener =
        new TabListener<AlbumsPickerFragment>(this, albumsLabel, AlbumsPickerFragment.class);

    tab.setTabListener(albumsTabListener);
    actionBar.addTab(tab);

    // Add the songs tab.
    String songsLabel = getResources().getString(R.string.songs);
    tab = actionBar.newTab();
    tab.setText(songsLabel);
    TabListener<SongsPickerFragment> songsTabListener =
        new TabListener<SongsPickerFragment>(this, songsLabel, SongsPickerFragment.class);

    tab.setTabListener(songsTabListener);
    actionBar.addTab(tab);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      getWindow().setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext));
      int topPadding = Common.getStatusBarHeight(mContext);
      View activityView = (View) findViewById(android.R.id.content);

      // Calculate ActionBar height
      TypedValue tv = new TypedValue();
      int actionBarHeight = 0;
      if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        actionBarHeight =
            TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
      }

      if (activityView != null) {
        activityView.setPadding(0, topPadding + actionBarHeight, 0, 0);
      }
    }
  }