OSDN Git Service

Open changelog in a Chrome custom tab
[android-x86/packages-apps-Taskbar.git] / app / src / playstore / java / com / farmerbb / taskbar / util / DependencyUtils.java
1 /* Copyright 2017 Braden Farmer
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 package com.farmerbb.taskbar.util;
17
18 import android.content.Context;
19 import android.content.Intent;
20 import android.net.Uri;
21 import android.os.Build;
22
23 import androidx.browser.customtabs.CustomTabsIntent;
24 import androidx.core.content.ContextCompat;
25
26 import com.farmerbb.taskbar.R;
27 import com.farmerbb.taskbar.activity.TaskerConditionActivity;
28 import com.mikepenz.foundation_icons_typeface_library.FoundationIcons;
29 import com.mikepenz.iconics.Iconics;
30
31 // Utility class meant for abstracting out all third-party dependencies.
32 // This allows the Android-x86 version of Taskbar to be built purely from AOSP source.
33 // TODO Do not make changes to this file without making corresponding changes to the Android-x86 version.
34
35 public class DependencyUtils {
36
37     private DependencyUtils() {}
38
39     public static CharSequence getKeyboardShortcutSummary(Context context) {
40         Iconics.registerFont(new FoundationIcons());
41         return new Iconics.IconicsBuilder()
42                 .ctx(context)
43                 .on(context.getString(R.string.tb_pref_description_keyboard_shortcut))
44                 .build();
45     }
46
47     static ToastInterface createToast(Context context, String message, int length) {
48         if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1)
49             return new ToastFrameworkImpl(context, message, length);
50         else
51             return new ToastCompatImpl(context, message, length);
52     }
53
54     public static void requestTaskerQuery(Context context) {
55         Intent query = new Intent(com.twofortyfouram.locale.api.Intent.ACTION_REQUEST_QUERY);
56         query.putExtra(com.twofortyfouram.locale.api.Intent.EXTRA_STRING_ACTIVITY_CLASS_NAME, TaskerConditionActivity.class.getName());
57         context.sendBroadcast(query);
58     }
59
60     public static void openChromeCustomTab(Context context, Uri uri) {
61         new CustomTabsIntent.Builder()
62                 .setToolbarColor(ContextCompat.getColor(context, R.color.tb_colorPrimary))
63                 .setSecondaryToolbarColor(ContextCompat.getColor(context, R.color.tb_main_activity_background))
64                 .setShowTitle(true)
65                 .addDefaultShareMenuItem()
66                 .build()
67                 .launchUrl(context, uri);
68     }
69 }