Search in sources :

Example 6 with ContextCompat.getDrawable

use of android.support.v4.content.ContextCompat.getDrawable in project android_packages_apps_Dialer by LineageOS.

the class ContactListItemView method setCallToAction.

/**
 * Sets whether the call to action is shown. For the {@link CallToAction} to be shown, it must be
 * supported as well.
 *
 * @param action {@link CallToAction} you want to display (if it's supported).
 * @param listener Listener to notify when the call to action is clicked.
 * @param position The position in the adapter of the call to action.
 */
public void setCallToAction(@CallToAction int action, Listener listener, int position) {
    mCallToAction = action;
    mPosition = position;
    Drawable drawable;
    int description;
    OnClickListener onClickListener;
    if (action == CALL_AND_SHARE) {
        drawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_phone_attach);
        drawable.setAutoMirrored(true);
        description = R.string.description_search_call_and_share;
        onClickListener = v -> listener.onCallAndShareIconClicked(position);
    } else if (action == VIDEO && mSupportVideoCall) {
        drawable = ContextCompat.getDrawable(getContext(), R.drawable.quantum_ic_videocam_vd_theme_24);
        drawable.setAutoMirrored(true);
        description = R.string.description_search_video_call;
        onClickListener = v -> listener.onVideoCallIconClicked(position);
    } else if (action == LIGHTBRINGER) {
        CallIntentBuilder.increaseLightbringerCallButtonAppearInSearchCount();
        drawable = ContextCompat.getDrawable(getContext(), R.drawable.quantum_ic_videocam_vd_theme_24);
        drawable.setAutoMirrored(true);
        description = R.string.description_search_video_call;
        onClickListener = v -> listener.onLightbringerIconClicked(position);
    } else {
        mCallToActionView.setVisibility(View.GONE);
        mCallToActionView.setOnClickListener(null);
        return;
    }
    mCallToActionView.setContentDescription(getContext().getString(description));
    mCallToActionView.setOnClickListener(onClickListener);
    mCallToActionView.setImageDrawable(drawable);
    mCallToActionView.setVisibility(View.VISIBLE);
}
Also used : Typeface(android.graphics.Typeface) Context(android.content.Context) Rect(android.graphics.Rect) Bundle(android.os.Bundle) CallIntentBuilder(com.android.dialer.callintent.CallIntentBuilder) Spannable(android.text.Spannable) ImageView(android.widget.ImageView) NonNull(android.support.annotation.NonNull) SelectionBoundsAdjuster(android.widget.AbsListView.SelectionBoundsAdjuster) Drawable(android.graphics.drawable.Drawable) ViewUtil(com.android.dialer.util.ViewUtil) TruncateAt(android.text.TextUtils.TruncateAt) TypedArray(android.content.res.TypedArray) Retention(java.lang.annotation.Retention) ArrayList(java.util.ArrayList) ColorStateList(android.content.res.ColorStateList) R(com.android.contacts.common.R) PhoneNumberUtilsCompat(com.android.contacts.common.compat.PhoneNumberUtilsCompat) Matcher(java.util.regex.Matcher) ContactsContract(android.provider.ContactsContract) AttributeSet(android.util.AttributeSet) MotionEvent(android.view.MotionEvent) Locale(java.util.Locale) SearchUtil(com.android.contacts.common.util.SearchUtil) ContactPresenceIconUtil(com.android.contacts.common.ContactPresenceIconUtil) View(android.view.View) Canvas(android.graphics.Canvas) ScaleType(android.widget.ImageView.ScaleType) ContactStatusUtil(com.android.contacts.common.ContactStatusUtil) Cursor(android.database.Cursor) Contacts(android.provider.ContactsContract.Contacts) Listener(com.android.contacts.common.list.PhoneNumberListAdapter.Listener) SearchSnippets(android.provider.ContactsContract.SearchSnippets) SpannableString(android.text.SpannableString) ContextCompat(android.support.v4.content.ContextCompat) QuickContactBadge(android.widget.QuickContactBadge) IntDef(android.support.annotation.IntDef) TextUtils(android.text.TextUtils) ViewGroup(android.view.ViewGroup) Color(android.graphics.Color) Gravity(android.view.Gravity) List(java.util.List) TextView(android.widget.TextView) TextHighlighter(com.android.contacts.common.format.TextHighlighter) TypedValue(android.util.TypedValue) Pattern(java.util.regex.Pattern) ContactDisplayUtils(com.android.contacts.common.util.ContactDisplayUtils) RetentionPolicy(java.lang.annotation.RetentionPolicy) Drawable(android.graphics.drawable.Drawable)

Example 7 with ContextCompat.getDrawable

use of android.support.v4.content.ContextCompat.getDrawable in project FastHub by k0shk0sh.

the class PullStatusViewHolder method bind.

@Override
public void bind(@NonNull PullRequestStatusModel pullRequestStatusModel) {
    if (pullRequestStatusModel.getState() != null) {
        StatusStateType stateType = pullRequestStatusModel.getState();
        stateImage.setImageResource(stateType.getDrawableRes());
        String mergeableState = pullRequestStatusModel.getMergeableState();
        boolean isBlocked = "blocked".equalsIgnoreCase(mergeableState);
        if (stateType == StatusStateType.failure) {
            stateImage.tintDrawableColor(red);
            if (pullRequestStatusModel.isMergable()) {
                status.setText(R.string.checks_failed);
            } else {
                status.setText(SpannableBuilder.builder().append(status.getResources().getString(R.string.checks_failed)).append("\n").append(status.getResources().getString(R.string.can_not_merge_pr)));
            }
        } else if (stateType == StatusStateType.pending) {
            if (pullRequestStatusModel.isMergable()) {
                stateImage.setImageResource(R.drawable.ic_check_small);
                stateImage.tintDrawableColor(green);
                status.setText(!isBlocked ? R.string.commit_can_be_merged : R.string.can_not_merge_pr);
            } else {
                stateImage.setImageResource(stateType.getDrawableRes());
                stateImage.tintDrawableColor(indigo);
                status.setText(R.string.checks_pending);
            }
        } else {
            stateImage.tintDrawableColor(green);
            if (pullRequestStatusModel.isMergable()) {
                status.setText(!isBlocked ? R.string.commit_can_be_merged : R.string.can_not_merge_pr);
            } else {
                status.setText(R.string.checks_passed);
            }
        }
    }
    if (pullRequestStatusModel.getStatuses() != null && !pullRequestStatusModel.getStatuses().isEmpty()) {
        SpannableBuilder builder = SpannableBuilder.builder();
        Stream.of(pullRequestStatusModel.getStatuses()).filter(statusesModel -> statusesModel != null && statusesModel.getState() != null && statusesModel.getTargetUrl() != null).forEach(statusesModel -> {
            if (!InputHelper.isEmpty(statusesModel.getTargetUrl())) {
                builder.append(ContextCompat.getDrawable(statuses.getContext(), statusesModel.getState().getDrawableRes()));
                builder.append(" ").append(statusesModel.getContext() != null ? statusesModel.getContext() + " " : "").url(statusesModel.getDescription(), v -> SchemeParser.launchUri(v.getContext(), statusesModel.getTargetUrl())).append("\n");
            }
        });
        if (!InputHelper.isEmpty(builder)) {
            statuses.setMovementMethod(LinkMovementMethod.getInstance());
            statuses.setText(builder);
            statuses.setVisibility(View.VISIBLE);
        } else {
            statuses.setVisibility(View.GONE);
        }
    } else {
        statuses.setVisibility(View.GONE);
    }
}
Also used : PullRequestStatusModel(com.fastaccess.data.dao.PullRequestStatusModel) BaseViewHolder(com.fastaccess.ui.widgets.recyclerview.BaseViewHolder) Stream(com.annimon.stream.Stream) ContextCompat(android.support.v4.content.ContextCompat) InputHelper(com.fastaccess.helper.InputHelper) BindColor(butterknife.BindColor) NonNull(android.support.annotation.NonNull) LinkMovementMethod(android.text.method.LinkMovementMethod) ViewGroup(android.view.ViewGroup) SchemeParser(com.fastaccess.provider.scheme.SchemeParser) SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder) BindView(butterknife.BindView) StatusStateType(com.fastaccess.data.dao.types.StatusStateType) ForegroundImageView(com.fastaccess.ui.widgets.ForegroundImageView) R(com.fastaccess.R) FontTextView(com.fastaccess.ui.widgets.FontTextView) View(android.view.View) StatusStateType(com.fastaccess.data.dao.types.StatusStateType) SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder)

Example 8 with ContextCompat.getDrawable

use of android.support.v4.content.ContextCompat.getDrawable in project Taskbar by farmerbb.

the class TaskbarService method drawTaskbar.

@SuppressLint("RtlHardcoded")
private void drawTaskbar() {
    IconCache.getInstance(this).clearCache();
    // Initialize layout params
    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    U.setCachedRotation(windowManager.getDefaultDisplay().getRotation());
    final WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, CompatUtils.getOverlayType(), WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, PixelFormat.TRANSLUCENT);
    // Determine where to show the taskbar on screen
    switch(U.getTaskbarPosition(this)) {
        case "bottom_left":
            layoutId = R.layout.taskbar_left;
            params.gravity = Gravity.BOTTOM | Gravity.LEFT;
            positionIsVertical = false;
            break;
        case "bottom_vertical_left":
            layoutId = R.layout.taskbar_vertical;
            params.gravity = Gravity.BOTTOM | Gravity.LEFT;
            positionIsVertical = true;
            break;
        case "bottom_right":
            layoutId = R.layout.taskbar_right;
            params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
            positionIsVertical = false;
            break;
        case "bottom_vertical_right":
            layoutId = R.layout.taskbar_vertical;
            params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
            positionIsVertical = true;
            break;
        case "top_left":
            layoutId = R.layout.taskbar_left;
            params.gravity = Gravity.TOP | Gravity.LEFT;
            positionIsVertical = false;
            break;
        case "top_vertical_left":
            layoutId = R.layout.taskbar_top_vertical;
            params.gravity = Gravity.TOP | Gravity.LEFT;
            positionIsVertical = true;
            break;
        case "top_right":
            layoutId = R.layout.taskbar_right;
            params.gravity = Gravity.TOP | Gravity.RIGHT;
            positionIsVertical = false;
            break;
        case "top_vertical_right":
            layoutId = R.layout.taskbar_top_vertical;
            params.gravity = Gravity.TOP | Gravity.RIGHT;
            positionIsVertical = true;
            break;
    }
    // Initialize views
    SharedPreferences pref = U.getSharedPreferences(this);
    boolean altButtonConfig = pref.getBoolean("alt_button_config", false);
    layout = (LinearLayout) LayoutInflater.from(U.wrapContext(this)).inflate(layoutId, null);
    taskbar = U.findViewById(layout, R.id.taskbar);
    scrollView = U.findViewById(layout, R.id.taskbar_scrollview);
    if (altButtonConfig) {
        space = U.findViewById(layout, R.id.space_alt);
        layout.findViewById(R.id.space).setVisibility(View.GONE);
    } else {
        space = U.findViewById(layout, R.id.space);
        layout.findViewById(R.id.space_alt).setVisibility(View.GONE);
    }
    space.setOnClickListener(v -> toggleTaskbar());
    startButton = U.findViewById(layout, R.id.start_button);
    int padding;
    if (pref.getBoolean("app_drawer_icon", false)) {
        startButton.setImageDrawable(ContextCompat.getDrawable(this, U.isBlissOs(this) ? R.drawable.bliss : R.mipmap.ic_launcher));
        padding = getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding_alt);
    } else {
        startButton.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.all_apps_button_icon));
        padding = getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding);
    }
    startButton.setPadding(padding, padding, padding, padding);
    startButton.setOnClickListener(ocl);
    startButton.setOnLongClickListener(view -> {
        openContextMenu();
        return true;
    });
    startButton.setOnGenericMotionListener((view, motionEvent) -> {
        if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY)
            openContextMenu();
        return false;
    });
    refreshInterval = (int) (Float.parseFloat(pref.getString("refresh_frequency", "2")) * 1000);
    if (refreshInterval == 0)
        refreshInterval = 100;
    sortOrder = pref.getString("sort_order", "false");
    runningAppsOnly = pref.getString("recents_amount", "past_day").equals("running_apps_only");
    switch(pref.getString("recents_amount", "past_day")) {
        case "past_day":
            searchInterval = System.currentTimeMillis() - AlarmManager.INTERVAL_DAY;
            break;
        case "app_start":
            long appStartTime = pref.getLong("time_of_service_start", System.currentTimeMillis());
            long deviceStartTime = System.currentTimeMillis() - SystemClock.elapsedRealtime();
            searchInterval = deviceStartTime > appStartTime ? deviceStartTime : appStartTime;
            break;
        case "show_all":
            searchInterval = 0;
            break;
    }
    Intent intent = new Intent("com.farmerbb.taskbar.HIDE_START_MENU");
    LocalBroadcastManager.getInstance(TaskbarService.this).sendBroadcast(intent);
    if (altButtonConfig) {
        button = U.findViewById(layout, R.id.hide_taskbar_button_alt);
        layout.findViewById(R.id.hide_taskbar_button).setVisibility(View.GONE);
    } else {
        button = U.findViewById(layout, R.id.hide_taskbar_button);
        layout.findViewById(R.id.hide_taskbar_button_alt).setVisibility(View.GONE);
    }
    try {
        button.setTypeface(Typeface.createFromFile("/system/fonts/Roboto-Regular.ttf"));
    } catch (RuntimeException e) {
    /* Gracefully fail */
    }
    updateButton(false);
    button.setOnClickListener(v -> toggleTaskbar());
    LinearLayout buttonLayout = U.findViewById(layout, altButtonConfig ? R.id.hide_taskbar_button_layout_alt : R.id.hide_taskbar_button_layout);
    if (buttonLayout != null)
        buttonLayout.setOnClickListener(v -> toggleTaskbar());
    LinearLayout buttonLayoutToHide = U.findViewById(layout, altButtonConfig ? R.id.hide_taskbar_button_layout : R.id.hide_taskbar_button_layout_alt);
    if (buttonLayoutToHide != null)
        buttonLayoutToHide.setVisibility(View.GONE);
    int backgroundTint = U.getBackgroundTint(this);
    int accentColor = U.getAccentColor(this);
    dashboardButton = U.findViewById(layout, R.id.dashboard_button);
    navbarButtons = U.findViewById(layout, R.id.navbar_buttons);
    dashboardEnabled = pref.getBoolean("dashboard", false);
    if (dashboardEnabled) {
        layout.findViewById(R.id.square1).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square2).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square3).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square4).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square5).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square6).setBackgroundColor(accentColor);
        dashboardButton.setOnClickListener(v -> LocalBroadcastManager.getInstance(TaskbarService.this).sendBroadcast(new Intent("com.farmerbb.taskbar.TOGGLE_DASHBOARD")));
    } else
        dashboardButton.setVisibility(View.GONE);
    if (pref.getBoolean("button_back", false)) {
        navbarButtonsEnabled = true;
        ImageView backButton = U.findViewById(layout, R.id.button_back);
        backButton.setVisibility(View.VISIBLE);
        backButton.setOnClickListener(v -> {
            U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_BACK);
            if (U.shouldCollapse(this, false))
                hideTaskbar(true);
        });
        backButton.setOnLongClickListener(v -> {
            InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            imm.showInputMethodPicker();
            if (U.shouldCollapse(this, false))
                hideTaskbar(true);
            return true;
        });
        backButton.setOnGenericMotionListener((view13, motionEvent) -> {
            if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
                InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                imm.showInputMethodPicker();
                if (U.shouldCollapse(this, false))
                    hideTaskbar(true);
            }
            return true;
        });
    }
    if (pref.getBoolean("button_home", false)) {
        navbarButtonsEnabled = true;
        ImageView homeButton = U.findViewById(layout, R.id.button_home);
        homeButton.setVisibility(View.VISIBLE);
        homeButton.setOnClickListener(v -> {
            U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_HOME);
            if (U.shouldCollapse(this, false))
                hideTaskbar(true);
        });
        homeButton.setOnLongClickListener(v -> {
            Intent voiceSearchIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
            voiceSearchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            try {
                startActivity(voiceSearchIntent);
            } catch (ActivityNotFoundException e) {
            /* Gracefully fail */
            }
            if (U.shouldCollapse(this, false))
                hideTaskbar(true);
            return true;
        });
        homeButton.setOnGenericMotionListener((view13, motionEvent) -> {
            if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
                Intent voiceSearchIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
                voiceSearchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                try {
                    startActivity(voiceSearchIntent);
                } catch (ActivityNotFoundException e) {
                /* Gracefully fail */
                }
                if (U.shouldCollapse(this, false))
                    hideTaskbar(true);
            }
            return true;
        });
    }
    if (pref.getBoolean("button_recents", false)) {
        navbarButtonsEnabled = true;
        ImageView recentsButton = U.findViewById(layout, R.id.button_recents);
        recentsButton.setVisibility(View.VISIBLE);
        recentsButton.setOnClickListener(v -> {
            U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_RECENTS);
            if (U.shouldCollapse(this, false))
                hideTaskbar(true);
        });
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            recentsButton.setOnLongClickListener(v -> {
                U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN);
                if (U.shouldCollapse(this, false))
                    hideTaskbar(true);
                return true;
            });
            recentsButton.setOnGenericMotionListener((view13, motionEvent) -> {
                if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
                    U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN);
                    if (U.shouldCollapse(this, false))
                        hideTaskbar(true);
                }
                return true;
            });
        }
    }
    if (!navbarButtonsEnabled)
        navbarButtons.setVisibility(View.GONE);
    layout.setBackgroundColor(backgroundTint);
    layout.findViewById(R.id.divider).setBackgroundColor(accentColor);
    button.setTextColor(accentColor);
    if (isFirstStart && FreeformHackHelper.getInstance().isInFreeformWorkspace())
        showTaskbar(false);
    else if (!pref.getBoolean("collapsed", false) && pref.getBoolean("taskbar_active", false))
        toggleTaskbar();
    if (pref.getBoolean("auto_hide_navbar", false))
        U.showHideNavigationBar(this, false);
    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
    lbm.unregisterReceiver(showReceiver);
    lbm.unregisterReceiver(hideReceiver);
    lbm.unregisterReceiver(tempShowReceiver);
    lbm.unregisterReceiver(tempHideReceiver);
    lbm.unregisterReceiver(startMenuAppearReceiver);
    lbm.unregisterReceiver(startMenuDisappearReceiver);
    lbm.registerReceiver(showReceiver, new IntentFilter("com.farmerbb.taskbar.SHOW_TASKBAR"));
    lbm.registerReceiver(hideReceiver, new IntentFilter("com.farmerbb.taskbar.HIDE_TASKBAR"));
    lbm.registerReceiver(tempShowReceiver, new IntentFilter("com.farmerbb.taskbar.TEMP_SHOW_TASKBAR"));
    lbm.registerReceiver(tempHideReceiver, new IntentFilter("com.farmerbb.taskbar.TEMP_HIDE_TASKBAR"));
    lbm.registerReceiver(startMenuAppearReceiver, new IntentFilter("com.farmerbb.taskbar.START_MENU_APPEARING"));
    lbm.registerReceiver(startMenuDisappearReceiver, new IntentFilter("com.farmerbb.taskbar.START_MENU_DISAPPEARING"));
    startRefreshingRecents();
    windowManager.addView(layout, params);
    isFirstStart = false;
}
Also used : Rect(android.graphics.Rect) LinearLayout(android.widget.LinearLayout) UsageEvents(android.app.usage.UsageEvents) PackageManager(android.content.pm.PackageManager) WindowManager(android.view.WindowManager) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) MainActivity(com.farmerbb.taskbar.MainActivity) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) MenuHelper(com.farmerbb.taskbar.util.MenuHelper) IconCache(com.farmerbb.taskbar.util.IconCache) IBinder(android.os.IBinder) PowerManager(android.os.PowerManager) UsageStats(android.app.usage.UsageStats) PointerIcon(android.view.PointerIcon) PinnedBlockedApps(com.farmerbb.taskbar.util.PinnedBlockedApps) Handler(android.os.Handler) Display(android.view.Display) View(android.view.View) Button(android.widget.Button) TargetApi(android.annotation.TargetApi) LauncherHelper(com.farmerbb.taskbar.util.LauncherHelper) Service(android.app.Service) IntentFilter(android.content.IntentFilter) ContextCompat(android.support.v4.content.ContextCompat) U(com.farmerbb.taskbar.util.U) AppEntry(com.farmerbb.taskbar.util.AppEntry) CompatUtils(com.farmerbb.taskbar.util.CompatUtils) BroadcastReceiver(android.content.BroadcastReceiver) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) LauncherApps(android.content.pm.LauncherApps) AccessibilityService(android.accessibilityservice.AccessibilityService) List(java.util.List) ActivityNotFoundException(android.content.ActivityNotFoundException) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) Typeface(android.graphics.Typeface) ActivityManager(android.app.ActivityManager) Context(android.content.Context) Space(android.widget.Space) ContextMenuActivity(com.farmerbb.taskbar.activity.ContextMenuActivity) Intent(android.content.Intent) SystemClock(android.os.SystemClock) PixelFormat(android.graphics.PixelFormat) InputMethodManager(android.view.inputmethod.InputMethodManager) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) UserHandle(android.os.UserHandle) RecognizerIntent(android.speech.RecognizerIntent) Build(android.os.Build) ContextMenuActivityDark(com.farmerbb.taskbar.activity.dark.ContextMenuActivityDark) UserManager(android.os.UserManager) BuildConfig(com.farmerbb.taskbar.BuildConfig) ApplicationType(com.farmerbb.taskbar.util.ApplicationType) AlarmManager(android.app.AlarmManager) R(com.farmerbb.taskbar.R) LayoutInflater(android.view.LayoutInflater) ColorUtils(android.support.v4.graphics.ColorUtils) Point(android.graphics.Point) Field(java.lang.reflect.Field) FreeformHackHelper(com.farmerbb.taskbar.util.FreeformHackHelper) UsageStatsManager(android.app.usage.UsageStatsManager) ResolveInfo(android.content.pm.ResolveInfo) Color(android.graphics.Color) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) Configuration(android.content.res.Configuration) InvisibleActivityFreeform(com.farmerbb.taskbar.activity.InvisibleActivityFreeform) Collections(java.util.Collections) HomeActivity(com.farmerbb.taskbar.activity.HomeActivity) IntentFilter(android.content.IntentFilter) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent) InputMethodManager(android.view.inputmethod.InputMethodManager) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) WindowManager(android.view.WindowManager) ActivityNotFoundException(android.content.ActivityNotFoundException) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout) SuppressLint(android.annotation.SuppressLint)

Example 9 with ContextCompat.getDrawable

use of android.support.v4.content.ContextCompat.getDrawable in project kiwix-android by kiwix.

the class KiwixMobileActivity method showRateDialog.

public void showRateDialog() {
    String title = getString(R.string.rate_dialog_title);
    String message = getString(R.string.rate_dialog_msg_1) + " " + getString(R.string.app_name) + getString(R.string.rate_dialog_msg_2);
    String positive = getString(R.string.rate_dialog_positive);
    String negative = getString(R.string.rate_dialog_negative);
    String neutral = getString(R.string.rate_dialog_neutral);
    new AlertDialog.Builder(this, dialogStyle()).setTitle(title).setMessage(message).setPositiveButton(positive, (dialog, id) -> {
        visitCounterPref.setNoThanksState(true);
        goToRateApp();
    }).setNegativeButton(negative, (dialog, id) -> {
        visitCounterPref.setNoThanksState(true);
    }).setNeutralButton(neutral, (dialog, id) -> {
        tempVisitCount = 0;
        visitCounterPref.setCount(tempVisitCount);
    }).setIcon(ContextCompat.getDrawable(this, R.mipmap.kiwix_icon)).show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) REQUEST_PREFERENCES(org.kiwix.kiwixmobile.utils.Constants.REQUEST_PREFERENCES) Bundle(android.os.Bundle) EXTRA_LIBRARY(org.kiwix.kiwixmobile.utils.Constants.EXTRA_LIBRARY) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) RESULT_HISTORY_CLEARED(org.kiwix.kiwixmobile.utils.Constants.RESULT_HISTORY_CLEARED) Drawable(android.graphics.drawable.Drawable) SDK_INT(android.os.Build.VERSION.SDK_INT) TAG_CURRENT_ARTICLES(org.kiwix.kiwixmobile.utils.Constants.TAG_CURRENT_ARTICLES) Manifest(android.Manifest) EXTRA_ZIM_FILE(org.kiwix.kiwixmobile.utils.Constants.EXTRA_ZIM_FILE) EXTRA_SEARCH_IN_TEXT(org.kiwix.kiwixmobile.search.SearchActivity.EXTRA_SEARCH_IN_TEXT) Handler(android.os.Handler) ForegroundColorSpan(android.text.style.ForegroundColorSpan) Log(android.util.Log) DimenUtils(org.kiwix.kiwixmobile.utils.DimenUtils) EXTRA_EXTERNAL_LINK(org.kiwix.kiwixmobile.utils.Constants.EXTRA_EXTERNAL_LINK) KiwixSearchWidget(org.kiwix.kiwixmobile.utils.KiwixSearchWidget) EXTRA_CHOSE_X_URL(org.kiwix.kiwixmobile.utils.Constants.EXTRA_CHOSE_X_URL) ContextCompat(android.support.v4.content.ContextCompat) EXTRA_BOOKMARK_CONTENTS(org.kiwix.kiwixmobile.utils.Constants.EXTRA_BOOKMARK_CONTENTS) StyleUtils.dialogStyle(org.kiwix.kiwixmobile.utils.StyleUtils.dialogStyle) TAG_CURRENT_FILE(org.kiwix.kiwixmobile.utils.Constants.TAG_CURRENT_FILE) ActivityCompat(android.support.v4.app.ActivityCompat) VERSION_CODES(android.os.Build.VERSION_CODES) EXTRA_BOOKMARK_CLICKED(org.kiwix.kiwixmobile.utils.Constants.EXTRA_BOOKMARK_CLICKED) TableClickListener(org.kiwix.kiwixmobile.TableDrawerAdapter.TableClickListener) EXTRA_IS_WIDGET_SEARCH(org.kiwix.kiwixmobile.utils.Constants.EXTRA_IS_WIDGET_SEARCH) EXTRA_IS_WIDGET_STAR(org.kiwix.kiwixmobile.utils.Constants.EXTRA_IS_WIDGET_STAR) TAG_KIWIX(org.kiwix.kiwixmobile.utils.Constants.TAG_KIWIX) Snackbar(android.support.design.widget.Snackbar) BaseActivity(org.kiwix.kiwixmobile.base.BaseActivity) CompatFindActionModeCallback(org.kiwix.kiwixmobile.views.CompatFindActionModeCallback) BOOKMARK_CHOSEN_REQUEST(org.kiwix.kiwixmobile.utils.Constants.BOOKMARK_CHOSEN_REQUEST) KiwixSettingsActivity(org.kiwix.kiwixmobile.settings.KiwixSettingsActivity) ButterKnife(butterknife.ButterKnife) NonNull(android.support.annotation.NonNull) ToolbarScrollingKiwixWebView(org.kiwix.kiwixmobile.views.web.ToolbarScrollingKiwixWebView) ArrayList(java.util.ArrayList) WebSettings(android.webkit.WebSettings) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) StyleUtils(org.kiwix.kiwixmobile.utils.StyleUtils) DrawerLayout(android.support.v4.widget.DrawerLayout) ComponentName(android.content.ComponentName) SpannableString(android.text.SpannableString) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) LanguageUtils(org.kiwix.kiwixmobile.utils.LanguageUtils) File(java.io.File) AppWidgetManager(android.appwidget.AppWidgetManager) RecyclerView(android.support.v7.widget.RecyclerView) AlertDialog(android.support.v7.app.AlertDialog) KiwixDatabase(org.kiwix.kiwixmobile.database.KiwixDatabase) OkHttpClient(okhttp3.OkHttpClient) TAG_FILE_SEARCHED(org.kiwix.kiwixmobile.utils.Constants.TAG_FILE_SEARCHED) SharedPreferences(android.content.SharedPreferences) Toolbar(android.support.v7.widget.Toolbar) DocumentSection(org.kiwix.kiwixmobile.TableDrawerAdapter.DocumentSection) Configuration(android.content.res.Configuration) NetworkUtils(org.kiwix.kiwixmobile.utils.NetworkUtils) LibraryFragment(org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment) FileReader(org.kiwix.kiwixmobile.utils.files.FileReader) ORIENTATION_LANDSCAPE(android.content.res.Configuration.ORIENTATION_LANDSCAPE) EXTRA_IS_WIDGET_VOICE(org.kiwix.kiwixmobile.utils.Constants.EXTRA_IS_WIDGET_VOICE) ImageButton(android.widget.ImageButton) ActionMode(android.view.ActionMode) LinearLayout(android.widget.LinearLayout) PackageManager(android.content.pm.PackageManager) WindowManager(android.view.WindowManager) CONTACT_EMAIL_ADDRESS(org.kiwix.kiwixmobile.utils.Constants.CONTACT_EMAIL_ADDRESS) BindView(butterknife.BindView) EXTRA_SEARCH(org.kiwix.kiwixmobile.utils.Constants.EXTRA_SEARCH) AttributeSet(android.util.AttributeSet) PREF_KIWIX_MOBILE(org.kiwix.kiwixmobile.utils.Constants.PREF_KIWIX_MOBILE) Locale(java.util.Locale) ActionMenuItemView(android.support.v7.view.menu.ActionMenuItemView) BookmarksDao(org.kiwix.kiwixmobile.database.BookmarksDao) View(android.view.View) Button(android.widget.Button) EXTRA_NOTIFICATION_ID(org.kiwix.kiwixmobile.utils.Constants.EXTRA_NOTIFICATION_ID) Animation(android.view.animation.Animation) WebView(android.webkit.WebView) KiwixWebView(org.kiwix.kiwixmobile.views.web.KiwixWebView) DocumentParser(org.kiwix.kiwixmobile.utils.DocumentParser) EXTRA_ZIM_FILE_2(org.kiwix.kiwixmobile.utils.Constants.EXTRA_ZIM_FILE_2) AnimatedProgressBar(org.kiwix.kiwixmobile.views.AnimatedProgressBar) TAG_CURRENT_TAB(org.kiwix.kiwixmobile.utils.Constants.TAG_CURRENT_TAB) PorterDuff(android.graphics.PorterDuff) TAG_CURRENT_POSITIONS(org.kiwix.kiwixmobile.utils.Constants.TAG_CURRENT_POSITIONS) ViewGroup(android.view.ViewGroup) RateAppCounter(org.kiwix.kiwixmobile.utils.RateAppCounter) REQUEST_FILE_SEARCH(org.kiwix.kiwixmobile.utils.Constants.REQUEST_FILE_SEARCH) List(java.util.List) ActivityNotFoundException(android.content.ActivityNotFoundException) RelativeLayout(android.widget.RelativeLayout) FileUtils(org.kiwix.kiwixmobile.utils.files.FileUtils) Context(android.content.Context) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) KeyEvent(android.view.KeyEvent) Intent(android.content.Intent) AudioManager(android.media.AudioManager) MenuItem(android.view.MenuItem) TabLayout(android.support.design.widget.TabLayout) GravityCompat(android.support.v4.view.GravityCompat) AnimationUtils(android.view.animation.AnimationUtils) Inject(javax.inject.Inject) Build(android.os.Build) KiwixTextToSpeech(org.kiwix.kiwixmobile.utils.KiwixTextToSpeech) RESULT_RESTART(org.kiwix.kiwixmobile.utils.Constants.RESULT_RESTART) LayoutInflater(android.view.LayoutInflater) BookmarksActivity(org.kiwix.kiwixmobile.bookmarks_view.BookmarksActivity) Color(android.graphics.Color) REQUEST_STORAGE_PERMISSION(org.kiwix.kiwixmobile.utils.Constants.REQUEST_STORAGE_PERMISSION) ToolbarStaticKiwixWebView(org.kiwix.kiwixmobile.views.web.ToolbarStaticKiwixWebView) REQUEST_FILE_SELECT(org.kiwix.kiwixmobile.utils.Constants.REQUEST_FILE_SELECT) SharedPreferenceUtil(org.kiwix.kiwixmobile.utils.SharedPreferenceUtil) EXTRA_CHOSE_X_TITLE(org.kiwix.kiwixmobile.utils.Constants.EXTRA_CHOSE_X_TITLE) ZimManageActivity(org.kiwix.kiwixmobile.zim_manager.ZimManageActivity) Activity(android.app.Activity) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) JSONArray(org.json.JSONArray) SearchActivity(org.kiwix.kiwixmobile.search.SearchActivity) SpannableString(android.text.SpannableString)

Example 10 with ContextCompat.getDrawable

use of android.support.v4.content.ContextCompat.getDrawable in project chefly_android by chef-ly.

the class RecipeListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recipe_list);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    // Progress bar for loading search
    spinner = (ProgressBar) findViewById(R.id.progressBar1);
    spinner.setVisibility(View.GONE);
    spinner.setIndeterminateDrawable(ContextCompat.getDrawable(this, R.drawable.customprogressbar));
    // Initialize recipe lists
    serverRecipes = new RecipeList();
    favoriteRecipes = new RecipeList();
    // Start AsyncTaskLoader to get FavoriteRecipes
    Credentials cred = CredentialsManager.getCredentials(getApplicationContext());
    String t = cred.getAccessToken();
    Log.d(TAG, "Token -> " + t);
    if (t != null) {
        RequestMethod requestPackageFavs = new RequestMethod();
        requestPackageFavs.setEndPoint(urlFavsString);
        requestPackageFavs.setMethod("GET");
        requestPackageFavs.setHeader("Authorization", "Bearer " + t);
        Bundle bundlefavs = new Bundle();
        bundlefavs.putParcelable("requestPackage", requestPackageFavs);
        getSupportLoaderManager().initLoader(FAVORTIESID, bundlefavs, this).forceLoad();
    } else {
        Toast.makeText(this, "Could not retrieve favorites, token is null", Toast.LENGTH_SHORT).show();
    }
    // PageViewer
    pager = (ViewPager) findViewById(R.id.viewpager);
    Bundle serv = new Bundle();
    serv.putString("title", "Recipes");
    serv.putString("pageNum", "1");
    serv.putString("search", "");
    server = new ListViewFragment();
    server.setArguments(serv);
    Bundle f = new Bundle();
    f.putString("title", "Favorites");
    f.putString("pageNum", "2");
    f.putString("search", "");
    favs = new ListViewFragment();
    favs.setArguments(f);
    ListViewFragment[] frags = { server, favs };
    pager.setAdapter(new RecipeListPagerAdapter(getSupportFragmentManager(), frags));
    pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            // Log.d(TAG, "Position -> " + position);
            if (position == 1) {
                favoritesHeader.setPaintFlags(favoritesHeader.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
                recipesHeader.setPaintFlags(0);
            // ingredientsHeader.setPaintFlags(0);
            } else {
                recipesHeader.setPaintFlags(recipesHeader.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
                favoritesHeader.setPaintFlags(0);
            // ingredientsHeader.setPaintFlags(0);
            }
        }

        @Override
        public void onPageSelected(int position) {
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    // Header links
    // ingredientsHeader = (TextView) findViewById(R.id.ingredientsHeader);
    favoritesHeader = (TextView) findViewById(R.id.favortiesHeader);
    recipesHeader = (TextView) findViewById(R.id.recipesHeader);
    View.OnClickListener headerListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (v.getId() == favoritesHeader.getId()) {
                favoritesHeader.setPaintFlags(favoritesHeader.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
                recipesHeader.setPaintFlags(0);
                // ingredientsHeader.setPaintFlags(0);
                pager.setCurrentItem(1);
            } else {
                recipesHeader.setPaintFlags(recipesHeader.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
                favoritesHeader.setPaintFlags(0);
                // ingredientsHeader.setPaintFlags(0);
                pager.setCurrentItem(0);
            }
        }
    };
    // ingredientsHeader.setOnClickListener(headerListener);
    favoritesHeader.setOnClickListener(headerListener);
    recipesHeader.setOnClickListener(headerListener);
    // Tool/Appbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // Navigation Drawer
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
Also used : NavigationView(android.support.design.widget.NavigationView) RequestMethod(com.se491.chef_ly.http.RequestMethod) Bundle(android.os.Bundle) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) ViewPager(android.support.v4.view.ViewPager) NavigationView(android.support.design.widget.NavigationView) SearchView(android.support.v7.widget.SearchView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Paint(android.graphics.Paint) RecipeList(com.se491.chef_ly.model.RecipeList) DrawerLayout(android.support.v4.widget.DrawerLayout) Credentials(com.auth0.android.result.Credentials) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

View (android.view.View)13 ImageView (android.widget.ImageView)10 Drawable (android.graphics.drawable.Drawable)9 TextView (android.widget.TextView)6 Bundle (android.os.Bundle)5 ContextCompat (android.support.v4.content.ContextCompat)5 ViewPager (android.support.v4.view.ViewPager)5 ViewGroup (android.view.ViewGroup)5 Context (android.content.Context)4 Intent (android.content.Intent)3 SharedPreferences (android.content.SharedPreferences)3 Color (android.graphics.Color)3 Handler (android.os.Handler)3 NonNull (android.support.annotation.NonNull)3 Fragment (android.support.v4.app.Fragment)3 RoundedBitmapDrawable (android.support.v4.graphics.drawable.RoundedBitmapDrawable)3 RecyclerView (android.support.v7.widget.RecyclerView)3 TypedValue (android.util.TypedValue)3 LayoutInflater (android.view.LayoutInflater)3 FrameLayout (android.widget.FrameLayout)3