Differential D12507 Diff 33025 src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandWidgetDataProvider.java
Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandWidgetDataProvider.java
- This file was added.
1 | package org.kde.kdeconnect.Plugins.RunCommandPlugin; | ||||
---|---|---|---|---|---|
2 | | ||||
3 | import android.content.Context; | ||||
4 | import android.content.Intent; | ||||
5 | import android.os.Build; | ||||
6 | import android.support.annotation.RequiresApi; | ||||
7 | import android.view.View; | ||||
8 | import android.widget.RemoteViews; | ||||
9 | import android.widget.RemoteViewsService; | ||||
10 | | ||||
11 | import org.kde.kdeconnect_tp.R; | ||||
12 | | ||||
13 | | ||||
14 | @RequiresApi( api = Build.VERSION_CODES.ICE_CREAM_SANDWICH ) | ||||
15 | public class RunCommandWidgetDataProvider implements RemoteViewsService.RemoteViewsFactory{ | ||||
16 | | ||||
17 | private RunCommandPlugin runCommandPlugin; | ||||
18 | private Context mContext; | ||||
19 | | ||||
20 | public RunCommandWidgetDataProvider( Context context, Intent intent ){ | ||||
21 | mContext = context; | ||||
22 | } | ||||
23 | | ||||
24 | private boolean checkPlugin(){ | ||||
25 | if( RunCommandWidget.getCurrentDevice() == null || !RunCommandWidget.getCurrentDevice().isReachable() ) | ||||
26 | return false; | ||||
27 | | ||||
28 | runCommandPlugin = RunCommandWidget.getCurrentDevice().getPlugin( RunCommandPlugin.class ); | ||||
29 | return runCommandPlugin != null; | ||||
30 | } | ||||
31 | | ||||
32 | @Override | ||||
33 | public void onCreate( ){ | ||||
34 | } | ||||
35 | | ||||
36 | @Override | ||||
37 | public void onDataSetChanged( ){ | ||||
38 | | ||||
39 | } | ||||
40 | | ||||
41 | @Override | ||||
42 | public void onDestroy( ){ | ||||
43 | } | ||||
44 | | ||||
45 | @Override | ||||
46 | public int getCount( ){ | ||||
47 | return checkPlugin() ? runCommandPlugin.getCommandItems().size( ) : 0; | ||||
48 | } | ||||
49 | | ||||
50 | @Override | ||||
51 | public RemoteViews getViewAt( int i ){ | ||||
52 | | ||||
53 | RemoteViews remoteView = new RemoteViews( mContext.getPackageName( ), R.layout.list_item_entry ); | ||||
54 | CommandEntry listItem = runCommandPlugin.getCommandItems().get( i ); | ||||
55 | | ||||
56 | final Intent configIntent = new Intent( mContext, RunCommandWidget.class ); | ||||
57 | configIntent.setAction( RunCommandWidget.RUN_COMMAND_ACTION ); | ||||
58 | configIntent.putExtra( RunCommandWidget.TARGET_COMMAND, listItem.getKey() ); | ||||
59 | configIntent.putExtra( RunCommandWidget.TARGET_DEVICE, RunCommandWidget.getCurrentDevice().getDeviceId() ); | ||||
60 | | ||||
61 | remoteView.setTextViewText( R.id.list_item_entry_title, listItem.getName( ) ); | ||||
62 | remoteView.setTextViewText( R.id.list_item_entry_summary, listItem.getCommand() ); | ||||
63 | remoteView.setViewVisibility( R.id.list_item_entry_summary, View.VISIBLE ); | ||||
64 | | ||||
65 | remoteView.setOnClickFillInIntent( R.id.list_item_entry, configIntent ); | ||||
66 | | ||||
67 | return remoteView; | ||||
68 | } | ||||
69 | | ||||
70 | @Override | ||||
71 | public RemoteViews getLoadingView( ){ | ||||
72 | return null; | ||||
73 | } | ||||
74 | | ||||
75 | @Override | ||||
76 | public int getViewTypeCount( ){ | ||||
77 | return 1; | ||||
78 | } | ||||
79 | | ||||
80 | @Override | ||||
81 | public long getItemId( int i ){ | ||||
82 | return runCommandPlugin.getCommandItems().get( i ).getKey().hashCode( ); | ||||
83 | } | ||||
84 | | ||||
85 | @Override | ||||
86 | public boolean hasStableIds( ){ | ||||
87 | return false; | ||||
88 | } | ||||
89 | } | ||||
90 | No newline at end of file |