diff options
7 files changed, 200 insertions, 2 deletions
diff --git a/packages/SystemUI/res/drawable/clipboard_empty.xml b/packages/SystemUI/res/drawable/clipboard_empty.xml new file mode 100644 index 000000000000..14a5ad2e6dda --- /dev/null +++ b/packages/SystemUI/res/drawable/clipboard_empty.xml @@ -0,0 +1,25 @@ +<!-- + Copyright (C) 2016 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the License); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an AS IS BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24.0dp" + android:height="24.0dp" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + <path + android:fillColor="#FFFFFFFF" + android:pathData="M19.0,2.0l-4.18,0.0C14.0,0.84 13.3,0.0 12.0,0.0c-1.3,0.0 -2.0,0.84 -2.82,2.0L5.0,2.0c-1.1,0.0 -2.0,0.9 -2.0,2.0l0.0,16.0c0.0,1.0 0.9,2.0 2.0,2.0l14.0,0.0c1.1,0.0 2.0,-0.9 2.0,-2.0L21.0,4.0c0.0,-1.1 -0.9,-2.0 -2.0,-2.0zm-7.0,0.0c0.55,0.0 1.0,0.45 1.0,1.0s-0.45,1.0 -1.0,1.0 -1.0,-0.45 -1.0,-1.0 0.45,-1.0 1.0,-1.0zm7.0,18.0L5.0,20.0L5.0,4.0l2.0,0.0l0.0,3.0l10.0,0.0L17.0,4.0l2.0,0.0l0.0,16.0z" /> +</vector> + diff --git a/packages/SystemUI/res/drawable/clipboard_full.xml b/packages/SystemUI/res/drawable/clipboard_full.xml new file mode 100644 index 000000000000..2d46870bebc1 --- /dev/null +++ b/packages/SystemUI/res/drawable/clipboard_full.xml @@ -0,0 +1,25 @@ +<!-- + Copyright (C) 2016 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the License); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an AS IS BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24.0dp" + android:height="24.0dp" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + <path + android:fillColor="#FFFFFFFF" + android:pathData="M19.0,2.0l-4.18,0.0C14.0,0.84 13.3,0.0 12.0,0.0c-1.3,0.0 -2.0,0.84 -2.82,2.0L5.0,2.0c-1.1,0.0 -2.0,0.9 -2.0,2.0l0.0,16.0c0.0,1.0 0.9,2.0 2.0,2.0l14.0,0.0c1.1,0.0 2.0,-0.9 2.0,-2.0L21.0,4.0c0.0,-1.1 -0.9,-2.0 -2.0,-2.0zm-7.0,0.0c0.55,0.0 1.0,0.45 1.0,1.0s-0.45,1.0 -1.0,1.0 -1.0,-0.45 -1.0,-1.0 0.45,-1.0 1.0,-1.0zm7.0,18.0L5.0,20.0L5.0,4.0l2.0,0.0l0.0,3.0l10.0,0.0L17.0,4.0l2.0,0.0l0.0,16.0z M 6,8 l 12,0 l 0,11 l -12,0 l 0,-11z" /> +</vector> + diff --git a/packages/SystemUI/res/layout/clipboard.xml b/packages/SystemUI/res/layout/clipboard.xml new file mode 100644 index 000000000000..441d6737e3fd --- /dev/null +++ b/packages/SystemUI/res/layout/clipboard.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2016 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<com.android.systemui.tuner.ClipboardView + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:systemui="http://schemas.android.com/apk/res-auto" + android:layout_width="@dimen/navigation_side_padding" + android:layout_height="match_parent" + android:layout_weight="0" + android:scaleType="center" + android:contentDescription="@string/clipboard" + /> + diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index c1b58d86d1b9..981aa6f40d67 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -1381,4 +1381,10 @@ <!-- SysUI Tuner: Adjust button width dialog title [CHAR LIMIT=60] --> <string name="adjust_button_width">Adjust button width</string> + <!-- SysUI Tuner: Nav bar button that holds the clipboard [CHAR LIMIT=30] --> + <string name="clipboard">Clipboard</string> + + <!-- SysUI Tuner: Description of nav bar button that holds the clipboard [CHAR LIMIT=NONE] --> + <string name="clipboard_description">The Clipboard allows items to be dragged directly to the clipboard. Items can also be dragged directly out of the clipboard when present.</string> + </resources> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java index d49e295a6323..864e16edbc31 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java @@ -43,6 +43,7 @@ public class NavigationBarInflaterView extends FrameLayout implements TunerServi public static final String HOME = "home"; public static final String RECENT = "recent"; public static final String NAVSPACE = "space"; + public static final String CLIPBOARD = "clipboard"; public static final String GRAVITY_SEPARATOR = ";"; public static final String BUTTON_SEPARATOR = ","; @@ -233,6 +234,8 @@ public class NavigationBarInflaterView extends FrameLayout implements TunerServi v = inflater.inflate(R.layout.menu_ime, parent, false); } else if (NAVSPACE.equals(button)) { v = inflater.inflate(R.layout.nav_key_space, parent, false); + } else if (CLIPBOARD.equals(button)) { + v = inflater.inflate(R.layout.clipboard, parent, false); } else { return null; } diff --git a/packages/SystemUI/src/com/android/systemui/tuner/ClipboardView.java b/packages/SystemUI/src/com/android/systemui/tuner/ClipboardView.java new file mode 100644 index 000000000000..63ed912a2259 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/tuner/ClipboardView.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package com.android.systemui.tuner; + +import com.android.systemui.R; + +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.ClipboardManager.OnPrimaryClipChangedListener; +import android.content.Context; +import android.util.AttributeSet; +import android.view.DragEvent; +import android.view.MotionEvent; +import android.view.View; +import android.widget.ImageView; + +public class ClipboardView extends ImageView implements OnPrimaryClipChangedListener { + + private static final int TARGET_COLOR = 0x4dffffff; + private final ClipboardManager mClipboardManager; + private ClipData mCurrentClip; + + public ClipboardView(Context context, AttributeSet attrs) { + super(context, attrs); + mClipboardManager = context.getSystemService(ClipboardManager.class); + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + startListening(); + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + stopListening(); + } + + @Override + public boolean onTouchEvent(MotionEvent ev) { + if (ev.getActionMasked() == MotionEvent.ACTION_DOWN && mCurrentClip != null) { + startPocketDrag(); + } + return super.onTouchEvent(ev); + } + + @Override + public boolean onDragEvent(DragEvent event) { + switch (event.getAction()) { + case DragEvent.ACTION_DRAG_ENTERED: + setBackgroundDragTarget(true); + break; + case DragEvent.ACTION_DROP: + mClipboardManager.setPrimaryClip(event.getClipData()); + case DragEvent.ACTION_DRAG_EXITED: + case DragEvent.ACTION_DRAG_ENDED: + setBackgroundDragTarget(false); + break; + } + return true; + } + + private void setBackgroundDragTarget(boolean isTarget) { + setBackgroundColor(isTarget ? TARGET_COLOR : 0); + } + + public void startPocketDrag() { + startDragAndDrop(mCurrentClip, new View.DragShadowBuilder(this), null, + View.DRAG_FLAG_GLOBAL); + } + + public void startListening() { + mClipboardManager.addPrimaryClipChangedListener(this); + onPrimaryClipChanged(); + } + + public void stopListening() { + mClipboardManager.removePrimaryClipChangedListener(this); + } + + @Override + public void onPrimaryClipChanged() { + mCurrentClip = mClipboardManager.getPrimaryClip(); + setImageResource(mCurrentClip != null + ? R.drawable.clipboard_full : R.drawable.clipboard_empty); + } +} diff --git a/packages/SystemUI/src/com/android/systemui/tuner/NavBarTuner.java b/packages/SystemUI/src/com/android/systemui/tuner/NavBarTuner.java index 5d0c145809ea..08424ddc6b32 100644 --- a/packages/SystemUI/src/com/android/systemui/tuner/NavBarTuner.java +++ b/packages/SystemUI/src/com/android/systemui/tuner/NavBarTuner.java @@ -45,6 +45,7 @@ import android.widget.TextView; import java.util.ArrayList; import java.util.List; +import static com.android.systemui.statusbar.phone.NavigationBarInflaterView.CLIPBOARD; import static com.android.systemui.statusbar.phone.NavigationBarInflaterView.SIZE_MOD_END; import static com.android.systemui.statusbar.phone.NavigationBarInflaterView.SIZE_MOD_START; import static com.android.systemui.statusbar.phone.NavigationBarInflaterView.extractButton; @@ -158,6 +159,8 @@ public class NavBarTuner extends Fragment implements TunerService.Tunable { return context.getString(R.string.space); } else if (button.startsWith(MENU_IME)) { return context.getString(R.string.menu_ime); + } else if (button.startsWith(CLIPBOARD)) { + return context.getString(R.string.clipboard); } return button; } @@ -348,9 +351,9 @@ public class NavBarTuner extends Fragment implements TunerService.Tunable { }); } - private void showAddDialog(Context context) { + private void showAddDialog(final Context context) { final String[] options = new String[] { - BACK, HOME, RECENT, MENU_IME, NAVSPACE, + BACK, HOME, RECENT, MENU_IME, NAVSPACE, CLIPBOARD, }; final CharSequence[] labels = new CharSequence[options.length]; for (int i = 0; i < options.length; i++) { @@ -362,6 +365,7 @@ public class NavBarTuner extends Fragment implements TunerService.Tunable { @Override public void onClick(DialogInterface dialog, int which) { int index = mButtons.size() - 1; + showAddedMessage(context, options[which]); mButtons.add(index, options[which]); mLabels.add(index, labels[which]); notifyItemInserted(index); @@ -370,6 +374,16 @@ public class NavBarTuner extends Fragment implements TunerService.Tunable { .show(); } + private void showAddedMessage(Context context, String button) { + if (CLIPBOARD.equals(button)) { + new AlertDialog.Builder(context) + .setTitle(R.string.clipboard) + .setMessage(R.string.clipboard_description) + .setPositiveButton(android.R.string.ok, null) + .show(); + } + } + private void bindClick(View view, Holder holder) { view.setOnClickListener(this); view.setTag(holder); |