Example usage for android.app Activity getTheme

List of usage examples for android.app Activity getTheme

Introduction

In this page you can find the example usage for android.app Activity getTheme.

Prototype

@Override
    public Resources.Theme getTheme() 

Source Link

Usage

From source file:com.eurecalab.eureca.ui.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;// w w  w.  j ava2 s  . co m
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view file_chooser_layout id set, try and inflate
            // it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }

        TypedValue color = new TypedValue();
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            int resource = textColorAccent ? R.attr.colorAccent : R.attr.colorPrimary;
            activity.getTheme().resolveAttribute(resource, color, true);

            tabTitleView.setTextColor(color.data);
        }
        tabTitleView.setTextSize(14);
    }
}

From source file:app.newbee.lib.swipeback.SwipeBackLayout.java

public void attachToActivity(Activity activity) {
    mActivity = activity;/*from   w ww .j  a va 2  s . c  o m*/
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView().findViewById(Window.ID_ANDROID_CONTENT);
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}

From source file:com.android.fastlibrary.ui.activity.swipeback.SwipeBackLayout.java

public void attachToActivity(Activity activity) {
    mActivity = activity;//w w  w. j a v  a  2s. co  m
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}

From source file:com.androzic.waypoint.WaypointInfo.java

@SuppressLint("NewApi")
private void updateWaypointInfo(double lat, double lon) {
    Androzic application = Androzic.getApplication();
    Activity activity = getActivity();
    Dialog dialog = getDialog();//from www  . j  a  v a  2  s.co  m
    View view = getView();

    WebView description = (WebView) view.findViewById(R.id.description);

    if ("".equals(waypoint.description)) {
        description.setVisibility(View.GONE);
    } else {
        String descriptionHtml;
        try {
            TypedValue tv = new TypedValue();
            Theme theme = activity.getTheme();
            Resources resources = getResources();
            theme.resolveAttribute(android.R.attr.textColorSecondary, tv, true);
            int secondaryColor = resources.getColor(tv.resourceId);
            String css = String.format(
                    "<style type=\"text/css\">html,body{margin:0;background:transparent} *{color:#%06X}</style>\n",
                    (secondaryColor & 0x00FFFFFF));
            descriptionHtml = css + waypoint.description;
            description.setWebViewClient(new WebViewClient() {
                @Override
                public void onPageFinished(WebView view, String url) {
                    view.setBackgroundColor(Color.TRANSPARENT);
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                        view.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
                }
            });
            description.setBackgroundColor(Color.TRANSPARENT);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                description.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
        } catch (Resources.NotFoundException e) {
            description.setBackgroundColor(Color.LTGRAY);
            descriptionHtml = waypoint.description;
        }

        WebSettings settings = description.getSettings();
        settings.setDefaultTextEncodingName("utf-8");
        settings.setAllowFileAccess(true);
        Uri baseUrl = Uri.fromFile(new File(application.dataPath));
        description.loadDataWithBaseURL(baseUrl.toString() + "/", descriptionHtml, "text/html", "utf-8", null);
    }

    String coords = StringFormatter.coordinates(" ", waypoint.latitude, waypoint.longitude);
    ((TextView) view.findViewById(R.id.coordinates)).setText(coords);

    if (waypoint.altitude != Integer.MIN_VALUE) {
        ((TextView) view.findViewById(R.id.altitude)).setText(StringFormatter.elevationH(waypoint.altitude));
    }

    double dist = Geo.distance(lat, lon, waypoint.latitude, waypoint.longitude);
    double bearing = Geo.bearing(lat, lon, waypoint.latitude, waypoint.longitude);
    bearing = application.fixDeclination(bearing);
    String distance = StringFormatter.distanceH(dist) + " " + StringFormatter.angleH(bearing);
    ((TextView) view.findViewById(R.id.distance)).setText(distance);

    if (waypoint.date != null)
        ((TextView) view.findViewById(R.id.date))
                .setText(DateFormat.getDateFormat(activity).format(waypoint.date) + " "
                        + DateFormat.getTimeFormat(activity).format(waypoint.date));
    else
        ((TextView) view.findViewById(R.id.date)).setVisibility(View.GONE);

    dialog.setTitle(waypoint.name);
}

From source file:org.openqa.selendroid.server.model.DefaultSelendroidDriver.java

@Override
@SuppressWarnings("deprecation")
public byte[] takeScreenshot() {
    ViewHierarchyAnalyzer viewAnalyzer = ViewHierarchyAnalyzer.getDefaultInstance();

    // TODO ddary review later, but with getRecentDecorView() it seems to work better
    // long drawingTime = 0;
    // View container = null;
    // for (View view : viewAnalyzer.getTopLevelViews()) {
    // if (view != null && view.isShown() && view.hasWindowFocus()
    // && view.getDrawingTime() > drawingTime) {
    // container = view;
    // drawingTime = view.getDrawingTime();
    // }//w ww  . j a va2 s .  c o m
    // }
    // final View mainView = container;
    final View mainView = viewAnalyzer.getRecentDecorView();
    if (mainView == null) {
        throw new SelendroidException("No open windows.");
    }
    done = false;
    long end = System.currentTimeMillis() + serverInstrumentation.getAndroidWait().getTimeoutInMillis();
    final byte[][] rawPng = new byte[1][1];
    ServerInstrumentation.getInstance().getCurrentActivity().runOnUiThread(new Runnable() {
        public void run() {
            synchronized (syncObject) {
                Display display = serverInstrumentation.getCurrentActivity().getWindowManager()
                        .getDefaultDisplay();
                Point size = new Point();
                try {
                    display.getSize(size);
                } catch (NoSuchMethodError ignore) { // Older than api level 13
                    size.x = display.getWidth();
                    size.y = display.getHeight();
                }

                // Get root view
                View view = mainView.getRootView();

                // Create the bitmap to use to draw the screenshot
                final Bitmap bitmap = Bitmap.createBitmap(size.x, size.y, Bitmap.Config.ARGB_8888);
                final Canvas canvas = new Canvas(bitmap);

                // Get current theme to know which background to use
                final Activity activity = serverInstrumentation.getCurrentActivity();
                final Theme theme = activity.getTheme();
                final TypedArray ta = theme
                        .obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
                final int res = ta.getResourceId(0, 0);
                final Drawable background = activity.getResources().getDrawable(res);

                // Draw background
                background.draw(canvas);

                // Draw views
                view.draw(canvas);

                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                if (!bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)) {
                    throw new RuntimeException("Error while compressing screenshot image.");
                }
                try {
                    stream.flush();
                    stream.close();
                } catch (IOException e) {
                    throw new RuntimeException("I/O Error while capturing screenshot: " + e.getMessage());
                } finally {
                    Closeable closeable = (Closeable) stream;
                    try {
                        if (closeable != null) {
                            closeable.close();
                        }
                    } catch (IOException ioe) {
                        // ignore
                    }
                }
                rawPng[0] = stream.toByteArray();
                mainView.destroyDrawingCache();
                done = true;
                syncObject.notify();
            }
        }
    });

    waitForDone(end, serverInstrumentation.getAndroidWait().getTimeoutInMillis(), "Failed to take screenshot.");
    return rawPng[0];
}

From source file:net.gsantner.opoc.preference.GsPreferenceFragmentCompat.java

@Override
@Deprecated// w w w.  ja v  a  2  s. c  om
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    Activity activity = getActivity();
    _appSettings = getAppSettings(activity);
    _cu = new ContextUtils(activity);
    getPreferenceManager().setSharedPreferencesName(getSharedPreferencesName());
    addPreferencesFromResource(getPreferenceResourceForInflation());

    if (activity != null && activity.getTheme() != null) {
        TypedArray array = activity.getTheme()
                .obtainStyledAttributes(new int[] { android.R.attr.colorBackground });
        int bgcolor = array.getColor(0, 0xFFFFFFFF);
        _defaultIconTintColor = _cu.shouldColorOnTopBeLight(bgcolor) ? Color.WHITE : Color.BLACK;
    }

    // on bottom
    afterOnCreate(savedInstanceState, activity);
}

From source file:io.selendroid.server.model.DefaultSelendroidDriver.java

@Override
@SuppressWarnings("deprecation")
public byte[] takeScreenshot() {
    ViewHierarchyAnalyzer viewAnalyzer = ViewHierarchyAnalyzer.getDefaultInstance();

    // TODO ddary review later, but with getRecentDecorView() it seems to work better
    // long drawingTime = 0;
    // View container = null;
    // for (View view : viewAnalyzer.getTopLevelViews()) {
    // if (view != null && view.isShown() && view.hasWindowFocus()
    // && view.getDrawingTime() > drawingTime) {
    // container = view;
    // drawingTime = view.getDrawingTime();
    // }/*  w w  w . j a v a2s  .  c  o m*/
    // }
    // final View mainView = container;
    final View mainView = viewAnalyzer.getRecentDecorView();
    if (mainView == null) {
        throw new SelendroidException("No open windows.");
    }
    done = false;
    long end = System.currentTimeMillis() + serverInstrumentation.getAndroidWait().getTimeoutInMillis();
    final byte[][] rawPng = new byte[1][1];
    ServerInstrumentation.getInstance().getCurrentActivity().runOnUiThread(new Runnable() {
        public void run() {
            synchronized (syncObject) {
                Display display = serverInstrumentation.getCurrentActivity().getWindowManager()
                        .getDefaultDisplay();
                Point size = new Point();
                try {
                    display.getSize(size);
                } catch (NoSuchMethodError ignore) { // Older than api level 13
                    size.x = display.getWidth();
                    size.y = display.getHeight();
                }

                // Get root view
                View view = mainView.getRootView();

                // Create the bitmap to use to draw the screenshot
                final Bitmap bitmap = Bitmap.createBitmap(size.x, size.y, Bitmap.Config.ARGB_8888);
                final Canvas canvas = new Canvas(bitmap);

                // Get current theme to know which background to use
                final Activity activity = serverInstrumentation.getCurrentActivity();
                final Theme theme = activity.getTheme();
                final TypedArray ta = theme
                        .obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
                final int res = ta.getResourceId(0, 0);
                final Drawable background = activity.getResources().getDrawable(res);

                // Draw background
                background.draw(canvas);

                // Draw views
                view.draw(canvas);

                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                if (!bitmap.compress(Bitmap.CompressFormat.PNG, 70, stream)) {
                    throw new RuntimeException("Error while compressing screenshot image.");
                }
                try {
                    stream.flush();
                    stream.close();
                } catch (IOException e) {
                    throw new RuntimeException("I/O Error while capturing screenshot: " + e.getMessage());
                } finally {
                    Closeable closeable = (Closeable) stream;
                    try {
                        if (closeable != null) {
                            closeable.close();
                        }
                    } catch (IOException ioe) {
                        // ignore
                    }
                }
                rawPng[0] = stream.toByteArray();
                mainView.destroyDrawingCache();
                done = true;
                syncObject.notify();
            }
        }
    });

    waitForDone(end, serverInstrumentation.getAndroidWait().getTimeoutInMillis(), "Failed to take screenshot.");
    return rawPng[0];
}

From source file:com.docd.purefm.adapters.BrowserBaseAdapter.java

protected BrowserBaseAdapter(@NonNull final Activity context) {
    if (sDrawableLruCache == null) {
        sDrawableLruCache = new DrawableLruCache<>();
    }/*from  w w w  .ja v  a2s.  c  o  m*/
    if (sMimeTypeIconCache == null) {
        sMimeTypeIconCache = new DrawableLruCache<>();
    }
    mSettings = Settings.getInstance(context);
    mPreviewHolder = PreviewHolder.getInstance(context);
    mTheme = context.getTheme();
    mResources = context.getResources();
    mHandler = new FileObserverEventHandler(this);
    mLayoutInflater = context.getLayoutInflater();
}

From source file:org.chromium.chrome.browser.download.ui.DownloadManagerUi.java

public DownloadManagerUi(Activity activity, boolean isOffTheRecord, ComponentName parentComponent) {
    mActivity = activity;//from  w w  w  . j  a v  a  2s  .co  m
    mBackendProvider = sProviderForTests == null ? new DownloadBackendProvider() : sProviderForTests;

    mMainView = (ViewGroup) LayoutInflater.from(activity).inflate(R.layout.download_main, null);

    mEmptyView = (TextView) mMainView.findViewById(R.id.empty_view);
    mEmptyView.setCompoundDrawablesWithIntrinsicBounds(null,
            VectorDrawableCompat.create(activity.getResources(), R.drawable.downloads_big, activity.getTheme()),
            null, null);
    mLoadingView = (LoadingView) mMainView.findViewById(R.id.loading_view);
    mLoadingView.showLoadingUI();

    mHistoryAdapter = new DownloadHistoryAdapter(isOffTheRecord, parentComponent);
    mHistoryAdapter.registerAdapterDataObserver(mAdapterObserver);
    mHistoryAdapter.initialize(mBackendProvider);
    addObserver(mHistoryAdapter);

    mSpaceDisplay = new SpaceDisplay(mMainView, mHistoryAdapter);
    mHistoryAdapter.registerAdapterDataObserver(mSpaceDisplay);
    mSpaceDisplay.onChanged();

    mFilterAdapter = new FilterAdapter();
    mFilterAdapter.initialize(this);
    addObserver(mFilterAdapter);

    mToolbar = (DownloadManagerToolbar) mMainView.findViewById(R.id.action_bar);
    mToolbar.setOnMenuItemClickListener(this);
    DrawerLayout drawerLayout = null;
    if (!DeviceFormFactor.isLargeTablet(activity)) {
        drawerLayout = (DrawerLayout) mMainView;
        addDrawerListener(drawerLayout);
    }
    mToolbar.initialize(mBackendProvider.getSelectionDelegate(), 0, drawerLayout, R.id.normal_menu_group,
            R.id.selection_mode_menu_group);
    addObserver(mToolbar);

    mFilterView = (ListView) mMainView.findViewById(R.id.section_list);
    mFilterView.setAdapter(mFilterAdapter);
    mFilterView.setOnItemClickListener(mFilterAdapter);

    mRecyclerView = (RecyclerView) mMainView.findViewById(R.id.recycler_view);
    mRecyclerView.setAdapter(mHistoryAdapter);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(activity));

    FadingShadowView shadow = (FadingShadowView) mMainView.findViewById(R.id.shadow);
    if (DeviceFormFactor.isLargeTablet(mActivity)) {
        shadow.setVisibility(View.GONE);
    } else {
        shadow.init(ApiCompatibilityUtils.getColor(mMainView.getResources(), R.color.toolbar_shadow_color),
                FadingShadow.POSITION_TOP);
    }

    mToolbar.setTitle(R.string.menu_downloads);

    mUndoDeletionSnackbarController = new UndoDeletionSnackbarController();
}

From source file:com.master.metehan.filtereagle.AdapterRule.java

public AdapterRule(Activity context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    this.context = context;
    this.filter = prefs.getBoolean("filter", false);

    if (prefs.getBoolean("dark_theme", false))
        colorChanged = Color.argb(128, Color.red(Color.DKGRAY), Color.green(Color.DKGRAY),
                Color.blue(Color.DKGRAY));
    else/*  w  w  w  . j a v a  2  s.c o  m*/
        colorChanged = Color.argb(128, Color.red(Color.LTGRAY), Color.green(Color.LTGRAY),
                Color.blue(Color.LTGRAY));

    TypedArray ta = context.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorSecondary });
    try {
        colorText = ta.getColor(0, 0);
    } finally {
        ta.recycle();
    }

    TypedValue tv = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorOn, tv, true);
    colorOn = tv.data;
    context.getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    colorOff = tv.data;

    colorGrayed = ContextCompat.getColor(context, R.color.colorGrayed);

    iconSize = Util.dips2pixels(48, context);
}