├── .gitignore
├── .travis.yml
├── Demo
├── context.gif
├── short.gif
├── shortNshare.gif
└── widget.gif
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── codingblocks
│ │ └── shortlr
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── codingblocks
│ │ │ └── shortlr
│ │ │ ├── ShortlrApp.java
│ │ │ ├── Utils.java
│ │ │ ├── activities
│ │ │ ├── GetPermissionActivity.java
│ │ │ ├── ShortenActivity.java
│ │ │ └── ShortenAndShareActivity.java
│ │ │ ├── api
│ │ │ └── ShortenApi.java
│ │ │ ├── models
│ │ │ ├── PostBody.java
│ │ │ └── Result.java
│ │ │ ├── services
│ │ │ └── CBWatcherService.java
│ │ │ ├── watcher
│ │ │ └── HomePressWatcher.java
│ │ │ └── widget
│ │ │ └── MyWidgetProvider.java
│ └── res
│ │ ├── drawable-hdpi
│ │ ├── clipboard_paste_button_black.9.png
│ │ ├── ic_arrow_back.png
│ │ ├── ic_content_cut_black_24dp.png
│ │ ├── ic_content_paste_black_24dp.png
│ │ ├── ic_unfold_less.png
│ │ └── scissors_black.9.png
│ │ ├── drawable-mdpi
│ │ ├── clipboard_paste_button_black.9.png
│ │ ├── ic_arrow_back.png
│ │ ├── ic_content_cut_black_24dp.png
│ │ ├── ic_content_paste_black_24dp.png
│ │ ├── ic_unfold_less.png
│ │ └── scissors_black.9.png
│ │ ├── drawable-xhdpi
│ │ ├── clipboard_paste_button_black.9.png
│ │ ├── ic_arrow_back.png
│ │ ├── ic_content_cut_black_24dp.png
│ │ ├── ic_content_paste_black_24dp.png
│ │ ├── ic_unfold_less.png
│ │ └── scissors_black.9.png
│ │ ├── drawable-xxhdpi
│ │ ├── clipboard_paste_button_black.9.png
│ │ ├── ic_arrow_back.png
│ │ ├── ic_content_cut_black_24dp.png
│ │ ├── ic_content_paste_black_24dp.png
│ │ ├── ic_unfold_less.png
│ │ └── scissors_black.9.png
│ │ ├── drawable-xxxhdpi
│ │ ├── clipboard_paste_button_black.9.png
│ │ ├── ic_arrow_back.png
│ │ ├── ic_content_cut_black_24dp.png
│ │ ├── ic_content_paste_black_24dp.png
│ │ ├── ic_unfold_less.png
│ │ └── scissors_black.9.png
│ │ ├── drawable
│ │ └── rounded_shape.xml
│ │ ├── layout
│ │ ├── activity_get_permission.xml
│ │ ├── activity_main.xml
│ │ ├── activity_shorten.xml
│ │ ├── activity_shorten_and_share.xml
│ │ ├── widget_layout.xml
│ │ └── window_layout.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ ├── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ │ └── xml
│ │ └── widget_info.xml
│ └── test
│ └── java
│ └── com
│ └── codingblocks
│ └── shortlr
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 | /captures
8 | ### JetBrains template
9 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
10 |
11 | *.iml
12 |
13 | ## Directory-based project format:
14 | .idea/
15 | # if you remove the above rule, at least ignore the following:
16 |
17 | # User-specific stuff:
18 | # .idea/workspace.xml
19 | # .idea/tasks.xml
20 | # .idea/dictionaries
21 |
22 | # Sensitive or high-churn files:
23 | # .idea/dataSources.ids
24 | # .idea/dataSources.xml
25 | # .idea/sqlDataSources.xml
26 | # .idea/dynamic.xml
27 | # .idea/uiDesigner.xml
28 |
29 | # Gradle:
30 | # .idea/gradle.xml
31 | # .idea/libraries
32 |
33 | # Mongo Explorer plugin:
34 | # .idea/mongoSettings.xml
35 |
36 | ## File-based project format:
37 | *.ipr
38 | *.iws
39 |
40 | ## Plugin-specific files:
41 |
42 | # IntelliJ
43 | /out/
44 |
45 | # mpeltonen/sbt-idea plugin
46 | .idea_modules/
47 |
48 | # JIRA plugin
49 | atlassian-ide-plugin.xml
50 |
51 | # Crashlytics plugin (for Android Studio and IntelliJ)
52 | com_crashlytics_export_strings.xml
53 | crashlytics.properties
54 | crashlytics-build.properties
55 | ### Android template
56 | # Built application files
57 | *.apk
58 | *.ap_
59 |
60 | # Files for the Dalvik VM
61 | *.dex
62 |
63 | # Java class files
64 | *.class
65 |
66 | # Generated files
67 | bin/
68 | gen/
69 |
70 | # Gradle files
71 | .gradle/
72 | build/
73 |
74 | # Local configuration file (sdk path, etc)
75 | local.properties
76 |
77 | # Proguard folder generated by Eclipse
78 | proguard/
79 |
80 | # Log Files
81 | *.log
82 |
83 | # Android Studio Navigation editor temp files
84 | .navigation/
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 |
3 | branches:
4 | only:
5 | - master
6 |
7 | script: "./gradlew clean assembleDebug"
8 |
9 | android:
10 | components:
11 | # Uncomment the lines below if you want to
12 | # use the latest revision of Android SDK Tools
13 | - tools
14 | - platform-tools
15 |
16 | # The BuildTools version used by your project
17 | - build-tools-25.0.2
18 |
19 | # The SDK version used to compile your project
20 | - android-25
21 |
22 | # Additional components
23 | # - extra-google-google_play_services
24 | # - extra-google-m2repository
25 | # - extra-android-m2repository
26 | # - addon-google_apis-google-19
27 |
28 | # Specify at least one system image,
29 | # if you need to run emulator(s) during your tests
30 | # - sys-img-armeabi-v7a-android-22
31 | # - sys-img-armeabi-v7a-android-17
32 |
33 | sudo: false
34 |
--------------------------------------------------------------------------------
/Demo/context.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/Demo/context.gif
--------------------------------------------------------------------------------
/Demo/short.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/Demo/short.gif
--------------------------------------------------------------------------------
/Demo/shortNshare.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/Demo/shortNshare.gif
--------------------------------------------------------------------------------
/Demo/widget.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/Demo/widget.gif
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Shortlr
2 |
3 | This is the android client for Coding Blocks Shortlr ([Github](https://github.com/coding-blocks/shortlr) , [Webapp](https://cb.lk/admin))
4 |
5 | ## Features
6 |
7 | #### 1. Home screen widget.
8 |
9 | 
10 |
11 | #### 2. Shorten on go.
12 |
13 | 
14 |
15 | #### 3. Short and share.
16 |
17 | 
18 |
19 | #### 4. Clipboard listener.
20 |
21 | 
22 |
23 | ## For Contributors
24 |
25 | Any UI changes are welcome. Please add a screenshot with the PR if there are UI changes.
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "com.codingblocks.shortlr"
8 | minSdkVersion 16
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.3.0'
28 | compile 'com.squareup.retrofit2:retrofit:+'
29 | compile 'com.android.support:cardview-v7:25.3.0'
30 | compile 'com.squareup.retrofit2:converter-gson:+'
31 | compile 'com.android.support:palette-v7:25.3.0'
32 | testCompile 'junit:junit:4.12'
33 | }
34 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/piyush0/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/codingblocks/shortlr/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.codingblocks.shortlr;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.codingblocks.shortlr", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
25 |
26 |
27 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
45 |
46 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingblocks/shortlr/ShortlrApp.java:
--------------------------------------------------------------------------------
1 | package com.codingblocks.shortlr;
2 |
3 | import android.app.Application;
4 | import android.content.Intent;
5 |
6 | import com.codingblocks.shortlr.services.CBWatcherService;
7 |
8 | /**
9 | * Created by piyush0 on 30/05/17.
10 | */
11 |
12 | public class ShortlrApp extends Application {
13 |
14 | @Override
15 | public void onCreate() {
16 | super.onCreate();
17 | startWatcherService();
18 | }
19 |
20 | private void startWatcherService() {
21 | Intent i = new Intent(this, CBWatcherService.class);
22 | startService(i);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingblocks/shortlr/Utils.java:
--------------------------------------------------------------------------------
1 | package com.codingblocks.shortlr;
2 |
3 | import android.content.ClipData;
4 | import android.content.ClipboardManager;
5 | import android.content.Context;
6 | import android.util.Log;
7 | import android.widget.Toast;
8 |
9 | import java.util.regex.Matcher;
10 | import java.util.regex.Pattern;
11 |
12 | import retrofit2.Call;
13 | import retrofit2.Callback;
14 | import retrofit2.Response;
15 | import retrofit2.Retrofit;
16 | import retrofit2.converter.gson.GsonConverterFactory;
17 |
18 | import static android.content.Context.CLIPBOARD_SERVICE;
19 |
20 | /**
21 | * Created by piyush0 on 11/04/17.
22 | */
23 |
24 | public class Utils {
25 |
26 | public static String getFromClip(Context context) {
27 | String retVal = null;
28 | ClipboardManager myClipboard;
29 | myClipboard = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
30 | ClipData abc = myClipboard.getPrimaryClip();
31 | if (abc != null) {
32 | ClipData.Item item = abc.getItemAt(0);
33 | retVal = item.getText().toString();
34 | }
35 | return retVal;
36 | }
37 |
38 | public static String saveToClipboard(String text, Context context) {
39 | ClipData myClip;
40 |
41 | myClip = ClipData.newPlainText("text", text);
42 | ClipboardManager myClipboard;
43 | myClipboard = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
44 | myClipboard.setPrimaryClip(myClip);
45 | Toast.makeText(context, "Link copied to clipboard", Toast.LENGTH_SHORT).show();
46 | return text;
47 | }
48 |
49 | public static String getHost(String url) {
50 | if (url == null || url.length() == 0)
51 | return "";
52 |
53 | int doubleslash = url.indexOf("//");
54 | if (doubleslash == -1)
55 | doubleslash = 0;
56 | else
57 | doubleslash += 2;
58 |
59 | int end = url.indexOf('/', doubleslash);
60 | end = end >= 0 ? end : url.length();
61 |
62 | int port = url.indexOf(':', doubleslash);
63 | end = (port > 0 && port < end) ? port : end;
64 |
65 | return url.substring(doubleslash, end);
66 | }
67 |
68 | private static final String URL_REGEX = "^((https?|ftp)://|(www|ftp)\\.)?[a-z0-9-]+(\\.[a-z0-9-]+)+([/?].*)?$";
69 |
70 | public static boolean isUrl(String str) {
71 | Pattern p = Pattern.compile(URL_REGEX);
72 | Matcher m = p.matcher(str);//replace with string to compare
73 | return m.find();
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingblocks/shortlr/activities/GetPermissionActivity.java:
--------------------------------------------------------------------------------
1 | package com.codingblocks.shortlr.activities;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.content.SharedPreferences;
6 | import android.net.Uri;
7 | import android.os.Build;
8 | import android.os.Bundle;
9 | import android.provider.Settings;
10 |
11 | import com.codingblocks.shortlr.R;
12 |
13 | public class GetPermissionActivity extends Activity {
14 | SharedPreferences sharedPreferences;
15 | private static final String SHARED_PREFS = "sp_permission_count";
16 | private static final String PERMISSION = "Permission";
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_get_permission);
22 |
23 | sharedPreferences = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
24 |
25 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
26 | if (!Settings.canDrawOverlays(GetPermissionActivity.this)) {
27 | int num = sharedPreferences.getInt(PERMISSION, 0);
28 | if (num == 0) {
29 | SharedPreferences.Editor editor = sharedPreferences.edit();
30 | editor.putInt(PERMISSION, num + 1);
31 | editor.apply();
32 | Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
33 | startActivityForResult(intent, 0);
34 | finish();
35 | }
36 | }
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingblocks/shortlr/activities/ShortenActivity.java:
--------------------------------------------------------------------------------
1 | package com.codingblocks.shortlr.activities;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.widget.Toast;
7 |
8 | import com.codingblocks.shortlr.R;
9 | import com.codingblocks.shortlr.Utils;
10 | import com.codingblocks.shortlr.api.ShortenApi;
11 | import com.codingblocks.shortlr.models.PostBody;
12 | import com.codingblocks.shortlr.models.Result;
13 | import com.codingblocks.shortlr.services.CBWatcherService;
14 |
15 | import retrofit2.Call;
16 | import retrofit2.Callback;
17 | import retrofit2.Response;
18 | import retrofit2.Retrofit;
19 | import retrofit2.converter.gson.GsonConverterFactory;
20 |
21 | public class ShortenActivity extends Activity {
22 | public static final String ACTION_MAIN = "android.intent.action.MAIN";
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_shorten);
28 |
29 |
30 | if (getIntent().getAction().equals(ACTION_MAIN)) {
31 | // This is the for the first time app is launched.
32 | finish();
33 | } else {
34 | String url = getIntent()
35 | .getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT).toString();
36 | boolean readOnly = getIntent()
37 | .getBooleanExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, false);
38 | if (Utils.isUrl(url)) {
39 | shorten(readOnly, url);
40 | } else {
41 | Toast.makeText(this, getString(R.string.not_a_url), Toast.LENGTH_SHORT).show();
42 | finish();
43 | }
44 | }
45 | }
46 |
47 | private void shorten(final Boolean readOnly, String urlToShort) {
48 | PostBody postBody = new PostBody(urlToShort, "", "");
49 | String urlToPost = getString(R.string.api_endpoint);
50 |
51 | Retrofit retrofit = new Retrofit
52 | .Builder()
53 | .addConverterFactory(GsonConverterFactory.create())
54 | .baseUrl(urlToPost)
55 | .build();
56 |
57 | ShortenApi shortenApi = retrofit.create(ShortenApi.class);
58 | shortenApi.getResult(postBody).enqueue(new Callback() {
59 |
60 | @Override
61 | public void onResponse(Call call, Response response) {
62 | String replacementText = getString(R.string.short_code_prepend) + response.body().getShortcode();
63 | if (readOnly) {
64 | Utils.saveToClipboard(replacementText, ShortenActivity.this);
65 | }
66 | Intent intent = new Intent();
67 | intent.putExtra(Intent.EXTRA_PROCESS_TEXT, replacementText);
68 | setResult(RESULT_OK, intent);
69 | finish();
70 | }
71 |
72 | @Override
73 | public void onFailure(Call call, Throwable t) {
74 | t.printStackTrace();
75 | }
76 | });
77 | }
78 |
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingblocks/shortlr/activities/ShortenAndShareActivity.java:
--------------------------------------------------------------------------------
1 | package com.codingblocks.shortlr.activities;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.pm.LauncherApps;
7 | import android.content.pm.PackageManager;
8 | import android.content.pm.ResolveInfo;
9 | import android.os.Bundle;
10 | import android.os.Parcelable;
11 | import android.util.Log;
12 | import android.widget.Toast;
13 |
14 | import com.codingblocks.shortlr.models.PostBody;
15 | import com.codingblocks.shortlr.R;
16 | import com.codingblocks.shortlr.models.Result;
17 | import com.codingblocks.shortlr.api.ShortenApi;
18 | import com.codingblocks.shortlr.Utils;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | import retrofit2.Call;
24 | import retrofit2.Callback;
25 | import retrofit2.Response;
26 | import retrofit2.Retrofit;
27 | import retrofit2.converter.gson.GsonConverterFactory;
28 |
29 | public class ShortenAndShareActivity extends Activity {
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_shorten_and_share);
35 |
36 | Intent intent = getIntent();
37 | String action = intent.getAction();
38 | String type = intent.getType();
39 |
40 | if (Intent.ACTION_SEND.equals(action) && type != null) {
41 | if ("text/plain".equals(type)) {
42 | String urlToShort = intent.getStringExtra(Intent.EXTRA_TEXT);
43 | String hostName = Utils.getHost(urlToShort);
44 | if (hostName.equals("cb.lk")) {
45 | Toast.makeText(this, "Please use another app to share the link!", Toast.LENGTH_SHORT).show();
46 | finish();
47 | } else {
48 | PostBody postBody = new PostBody(urlToShort, "", "");
49 |
50 | String urlToPost = getString(R.string.api_endpoint);
51 | Retrofit retrofit = new Retrofit
52 | .Builder()
53 | .addConverterFactory(GsonConverterFactory.create())
54 | .baseUrl(urlToPost)
55 | .build();
56 | ShortenApi shortenApi = retrofit.create(ShortenApi.class);
57 |
58 | shortenApi.getResult(postBody).enqueue(new Callback() {
59 |
60 | @Override
61 | public void onResponse(Call call, Response response) {
62 |
63 | String shortenedURL = getString(R.string.short_code_prepend) + response.body().getShortcode();
64 |
65 | PackageManager pm = getPackageManager();
66 | List targetIntents = new ArrayList();
67 |
68 | Intent i = new Intent(Intent.ACTION_SEND);
69 | i.setType("text/plain");
70 | List activities = pm.queryIntentActivities(i, 0);
71 |
72 | for (ResolveInfo currentInfo : activities) {
73 | String packageName = currentInfo.activityInfo.packageName;
74 | if (!getPackageName().equals(packageName)) {
75 | Intent targetIntent = new Intent(Intent.ACTION_SEND); // TRY ADDING EXPORT DATA ie url
76 | targetIntent.setType("text/plain");
77 | targetIntent.putExtra(Intent.EXTRA_SUBJECT, "Sharing URL");
78 | targetIntent.putExtra(Intent.EXTRA_TEXT, shortenedURL);
79 | targetIntent.setPackage(packageName);
80 | targetIntents.add(targetIntent);
81 | }
82 | }
83 |
84 | Intent chooserIntent = Intent.createChooser(targetIntents.remove(0), "Share URL");
85 | chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetIntents.toArray(new Parcelable[] {}));
86 | startActivity(chooserIntent);
87 | finish();
88 | }
89 |
90 | @Override
91 | public void onFailure(Call call, Throwable t) {
92 | t.printStackTrace();
93 | }
94 | });
95 | }
96 | }
97 | }
98 | }
99 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codingblocks/shortlr/api/ShortenApi.java:
--------------------------------------------------------------------------------
1 | package com.codingblocks.shortlr.api;
2 |
3 | import com.codingblocks.shortlr.models.PostBody;
4 | import com.codingblocks.shortlr.models.Result;
5 |
6 | import retrofit2.Call;
7 | import retrofit2.http.Body;
8 | import retrofit2.http.POST;
9 |
10 | /**
11 | * Created by piyush0 on 11/04/17.
12 | */
13 |
14 | public interface ShortenApi {
15 | @POST("shorten")
16 | Call getResult(@Body PostBody postBody);
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingblocks/shortlr/models/PostBody.java:
--------------------------------------------------------------------------------
1 | package com.codingblocks.shortlr.models;
2 |
3 | /**
4 | * Created by piyush0 on 11/04/17.
5 | */
6 |
7 | public class PostBody {
8 | private String url;
9 | private String secret;
10 | private String code;
11 |
12 | public PostBody(String url, String secret, String code) {
13 | this.url = url;
14 | this.secret = secret;
15 | this.code = code;
16 | }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingblocks/shortlr/models/Result.java:
--------------------------------------------------------------------------------
1 | package com.codingblocks.shortlr.models;
2 |
3 | /**
4 | * Created by piyush0 on 11/04/17.
5 | */
6 |
7 | public class Result {
8 | private String shortcode;
9 | private Boolean existed;
10 | private String longURL;
11 |
12 | public String getShortcode() {
13 | return shortcode;
14 | }
15 |
16 | public void setShortcode(String shortcode) {
17 | this.shortcode = shortcode;
18 | }
19 |
20 | public Boolean getExisted() {
21 | return existed;
22 | }
23 |
24 | public void setExisted(Boolean existed) {
25 | this.existed = existed;
26 | }
27 |
28 | public String getLongURL() {
29 | return longURL;
30 | }
31 |
32 | public void setLongURL(String longURL) {
33 | this.longURL = longURL;
34 | }
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingblocks/shortlr/services/CBWatcherService.java:
--------------------------------------------------------------------------------
1 | package com.codingblocks.shortlr.services;
2 |
3 | import android.app.Service;
4 | import android.content.ClipData;
5 | import android.content.ClipDescription;
6 | import android.content.ClipboardManager;
7 | import android.content.ClipboardManager.OnPrimaryClipChangedListener;
8 | import android.content.Context;
9 | import android.content.Intent;
10 | import android.graphics.Color;
11 | import android.os.Build;
12 | import android.os.IBinder;
13 | import android.provider.Settings;
14 | import android.view.Gravity;
15 | import android.view.KeyEvent;
16 | import android.view.View;
17 | import android.view.WindowManager;
18 | import android.view.animation.AccelerateDecelerateInterpolator;
19 | import android.view.animation.ScaleAnimation;
20 | import android.widget.ImageView;
21 |
22 | import com.codingblocks.shortlr.R;
23 | import com.codingblocks.shortlr.Utils;
24 | import com.codingblocks.shortlr.activities.GetPermissionActivity;
25 | import com.codingblocks.shortlr.api.ShortenApi;
26 | import com.codingblocks.shortlr.models.PostBody;
27 | import com.codingblocks.shortlr.models.Result;
28 | import com.codingblocks.shortlr.watcher.HomePressWatcher;
29 |
30 | import java.util.regex.Matcher;
31 | import java.util.regex.Pattern;
32 |
33 | import retrofit2.Call;
34 | import retrofit2.Callback;
35 | import retrofit2.Response;
36 | import retrofit2.Retrofit;
37 | import retrofit2.converter.gson.GsonConverterFactory;
38 |
39 |
40 | public class CBWatcherService extends Service {
41 | public static final String URL_REGEX = "^((https?|ftp)://|(www|ftp)\\.)?[a-z0-9-]+(\\.[a-z0-9-]+)+([/?].*)?$";
42 | private WindowManager manager = null;
43 | private View view = null;
44 | private OnPrimaryClipChangedListener listener = new OnPrimaryClipChangedListener() {
45 | public void onPrimaryClipChanged() {
46 |
47 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
48 | if (Settings.canDrawOverlays(CBWatcherService.this)) {
49 | performClipboardCheck();
50 | } else {
51 | Intent i = new Intent(CBWatcherService.this, GetPermissionActivity.class);
52 | i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
53 | startActivity(i);
54 | }
55 | } else {
56 | performClipboardCheck();
57 | }
58 | }
59 | };
60 |
61 | @Override
62 | public void onCreate() {
63 | ((ClipboardManager) getSystemService(CLIPBOARD_SERVICE)).addPrimaryClipChangedListener(listener);
64 | }
65 |
66 | @Override
67 | public int onStartCommand(Intent intent, int flags, int startId) {
68 | return START_STICKY;
69 | }
70 |
71 | @Override
72 | public IBinder onBind(Intent intent) {
73 | return null;
74 | }
75 |
76 | private void performClipboardCheck() {
77 | ClipboardManager cb = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
78 | if (cb.hasPrimaryClip()) {
79 | ClipData cd = cb.getPrimaryClip();
80 |
81 | if (cd.getDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
82 | String clipboardText = cd.getItemAt(0).getText().toString();
83 | Pattern p = Pattern.compile(URL_REGEX);
84 | Matcher m = p.matcher(clipboardText);
85 | if (m.find()) {
86 | if (!Utils.getHost(clipboardText).equals(getString(R.string.host))) {
87 | showView(clipboardText);
88 | }
89 | }
90 |
91 | }
92 | }
93 | }
94 |
95 | public void showView(final String url) {
96 | manager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
97 | WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
98 | layoutParams.gravity = Gravity.CENTER;
99 | layoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
100 | layoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
101 | layoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
102 | layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
103 | layoutParams.alpha = 1.0f;
104 | layoutParams.packageName = getPackageName();
105 | layoutParams.buttonBrightness = 1f;
106 | layoutParams.windowAnimations = android.R.style.Animation_Dialog;
107 |
108 | view = View.inflate(getApplicationContext(), R.layout.window_layout, null);
109 | ScaleAnimation scale = new ScaleAnimation(0, 1, 0, 1, ScaleAnimation.RELATIVE_TO_SELF, .5f, ScaleAnimation.RELATIVE_TO_SELF, .5f);
110 | scale.setDuration(300);
111 | scale.setInterpolator(new AccelerateDecelerateInterpolator());
112 | view.startAnimation(scale);
113 | view.setBackgroundColor(Color.parseColor("#ffffff"));
114 | final HomePressWatcher homePressWatcher = new HomePressWatcher(view.getContext());
115 | // solution for home button press and recentapps press
116 | homePressWatcher.setIntereceptor(new HomePressWatcher.onHomePressed() {
117 | @Override
118 | public void onHomeButtonPressed() {
119 | homePressWatcher.stopWatch();
120 | removeView();
121 | }
122 | });
123 | homePressWatcher.startWatch();
124 | // solution for back key press
125 | view.setOnKeyListener(new View.OnKeyListener() {
126 | @Override
127 | public boolean onKey(View v, int keyCode, KeyEvent event) {
128 | removeView();
129 | return false;
130 | }
131 | });
132 | view.requestFocus();
133 | view.setFocusable(true);
134 | view.setFocusableInTouchMode(true);
135 |
136 |
137 | ImageView yesButton = (ImageView) view.findViewById(R.id.yesButton);
138 | ImageView noButton = (ImageView) view.findViewById(R.id.noButton);
139 | yesButton.setOnClickListener(new View.OnClickListener() {
140 |
141 | @Override
142 | public void onClick(View v) {
143 | PostBody postBody = new PostBody(url, null, null);
144 |
145 | String urlToPost = getString(R.string.api_endpoint);
146 | Retrofit retrofit = new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create()).baseUrl(urlToPost).build();
147 | ShortenApi shortenApi = retrofit.create(ShortenApi.class);
148 |
149 | shortenApi.getResult(postBody).enqueue(new Callback() {
150 |
151 | @Override
152 | public void onResponse(Call call, Response response) {
153 | String shortUrl = getString(R.string.short_code_prepend) + response.body().getShortcode();
154 | Utils.saveToClipboard(shortUrl, CBWatcherService.this);
155 | removeView();
156 |
157 | }
158 |
159 | @Override
160 | public void onFailure(Call call, Throwable t) {
161 | t.printStackTrace();
162 | }
163 | });
164 |
165 |
166 | }
167 | });
168 | noButton.setOnClickListener(new View.OnClickListener() {
169 |
170 | @Override
171 | public void onClick(View v) {
172 | removeView();
173 | }
174 | });
175 | manager.addView(view, layoutParams);
176 | }
177 |
178 | private void removeView() {
179 | if (view != null) {
180 | manager.removeView(view);
181 | view = null;
182 | }
183 | }
184 |
185 |
186 | }
187 |
188 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingblocks/shortlr/watcher/HomePressWatcher.java:
--------------------------------------------------------------------------------
1 | package com.codingblocks.shortlr.watcher;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.IntentFilter;
7 | import android.util.Log;
8 | import android.view.View;
9 | import android.view.Window;
10 | import android.view.WindowManager;
11 |
12 | /**
13 | * Created by panross on 22/5/17.
14 | */
15 |
16 | public class HomePressWatcher {
17 |
18 | public interface onHomePressed{
19 | void onHomeButtonPressed();
20 | }
21 |
22 |
23 | Context context;
24 | onHomePressed interceptor;
25 | InterceptReceiver receiver;
26 |
27 | public HomePressWatcher(Context context)
28 | {
29 | this.context=context;
30 | }
31 |
32 | public void setIntereceptor(onHomePressed intereceptor)
33 | {
34 | this.interceptor=intereceptor;
35 | receiver=new InterceptReceiver();
36 | }
37 |
38 | public void startWatch()
39 | {
40 | context.registerReceiver(receiver, new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
41 | }
42 |
43 |
44 | public void stopWatch()
45 | {
46 | context.unregisterReceiver(receiver);
47 | }
48 |
49 | class InterceptReceiver extends BroadcastReceiver {
50 |
51 | @Override
52 | public void onReceive(Context context, Intent intent) {
53 | String action=intent.getAction();
54 | if(action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS))
55 | {
56 | String reason=intent.getStringExtra("reason");
57 | if(reason.equals("homekey") || reason.equals("recentapps"))
58 | {
59 | interceptor.onHomeButtonPressed();
60 | }
61 | }
62 | }
63 | }
64 |
65 |
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codingblocks/shortlr/widget/MyWidgetProvider.java:
--------------------------------------------------------------------------------
1 | package com.codingblocks.shortlr.widget;
2 |
3 | import android.app.PendingIntent;
4 | import android.appwidget.AppWidgetManager;
5 | import android.appwidget.AppWidgetProvider;
6 | import android.content.ComponentName;
7 | import android.content.Context;
8 | import android.content.Intent;
9 | import android.content.SharedPreferences;
10 | import android.util.Log;
11 | import android.widget.RemoteViews;
12 | import android.widget.Toast;
13 |
14 | import com.codingblocks.shortlr.models.PostBody;
15 | import com.codingblocks.shortlr.R;
16 | import com.codingblocks.shortlr.models.Result;
17 | import com.codingblocks.shortlr.api.ShortenApi;
18 | import com.codingblocks.shortlr.Utils;
19 |
20 | import retrofit2.Call;
21 | import retrofit2.Callback;
22 | import retrofit2.Response;
23 | import retrofit2.Retrofit;
24 | import retrofit2.converter.gson.GsonConverterFactory;
25 |
26 | /**
27 | * Created by piyush0 on 11/04/17.
28 | */
29 |
30 | public class MyWidgetProvider extends AppWidgetProvider {
31 |
32 | private static final String ShortenClick = "myOnClickTag1";
33 | private static final String PasteClick = "myOnClickTag2";
34 | public static final String MyPREFERENCES = "Prefs";
35 |
36 |
37 | @Override
38 | public void onUpdate(Context context, AppWidgetManager appWidgetManager,
39 | int[] appWidgetIds) {
40 |
41 | // Get all ids
42 | ComponentName thisWidget = new ComponentName(context,
43 | MyWidgetProvider.class);
44 | int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
45 | for (int widgetId : allWidgetIds) {
46 |
47 | RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
48 |
49 | remoteViews.setOnClickPendingIntent(R.id.widget_btn_shorten, getPendingSelfIntent(context, ShortenClick));
50 | remoteViews.setOnClickPendingIntent(R.id.widget_btn_paste, getPendingSelfIntent(context, PasteClick));
51 |
52 | appWidgetManager.updateAppWidget(widgetId, remoteViews);
53 |
54 | }
55 | }
56 |
57 | protected PendingIntent getPendingSelfIntent(Context context, String action) {
58 | Intent intent = new Intent(context, getClass());
59 | intent.setAction(action);
60 | return PendingIntent.getBroadcast(context, 0, intent, 0);
61 | }
62 |
63 | @Override
64 | public void onReceive(final Context context, Intent intent) {
65 | super.onReceive(context, intent);
66 | SharedPreferences sharedPreferences = context.getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
67 | String url = sharedPreferences.getString("url", "");
68 | setTextOnTv(context, url);
69 | if (ShortenClick.equals(intent.getAction())) {
70 | if (!Utils.isUrl(url)) {
71 | Toast.makeText(context, "Not a url", Toast.LENGTH_SHORT).show();
72 | } else {
73 | if (Utils.getHost(url).equals(context.getString(R.string.host))) {
74 | Toast.makeText(context, "Already a short url", Toast.LENGTH_SHORT).show();
75 | } else {
76 | getShortenedUrl(url, context);
77 | }
78 | }
79 |
80 | } else if (PasteClick.equals(intent.getAction())) {
81 |
82 | String text = Utils.getFromClip(context);
83 | setTextOnTv(context, text);
84 | saveToSharedPrefs(text, context);
85 | }
86 | }
87 |
88 | private void saveToSharedPrefs(String str, Context context) {
89 | SharedPreferences sharedpreferences = context.getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
90 | SharedPreferences.Editor editor = sharedpreferences.edit();
91 | editor.putString("url", str);
92 | editor.apply();
93 | }
94 |
95 | private void setTextOnTv(Context context, String text) {
96 | RemoteViews views = new RemoteViews(context.getPackageName(),
97 | R.layout.widget_layout);
98 | views.setTextViewText(R.id.widget_tv_url, text);
99 | AppWidgetManager.getInstance(context).updateAppWidget(
100 | new ComponentName(context, MyWidgetProvider.class), views);
101 | }
102 |
103 | public void getShortenedUrl(String url, final Context context) {
104 | PostBody postBody = new PostBody(url, "", "");
105 | final String[] shortURL = {""};
106 | String urlToPost = context.getString(R.string.api_endpoint);
107 | Retrofit retrofit = new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create()).baseUrl(urlToPost).build();
108 | ShortenApi shortenApi = retrofit.create(ShortenApi.class);
109 |
110 | shortenApi.getResult(postBody).enqueue(new Callback() {
111 |
112 | @Override
113 | public void onResponse(Call call, Response response) {
114 | shortURL[0] = context.getString(R.string.short_code_prepend) + response.body().getShortcode();
115 | saveToSharedPrefs(shortURL[0], context);
116 | setTextOnTv(context, shortURL[0]);
117 | Utils.saveToClipboard(shortURL[0], context);
118 | }
119 |
120 | @Override
121 | public void onFailure(Call call, Throwable t) {
122 | t.printStackTrace();
123 | }
124 | });
125 |
126 | }
127 |
128 |
129 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/clipboard_paste_button_black.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-hdpi/clipboard_paste_button_black.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-hdpi/ic_arrow_back.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_content_cut_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-hdpi/ic_content_cut_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_content_paste_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-hdpi/ic_content_paste_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_unfold_less.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-hdpi/ic_unfold_less.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/scissors_black.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-hdpi/scissors_black.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/clipboard_paste_button_black.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-mdpi/clipboard_paste_button_black.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-mdpi/ic_arrow_back.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_content_cut_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-mdpi/ic_content_cut_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_content_paste_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-mdpi/ic_content_paste_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_unfold_less.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-mdpi/ic_unfold_less.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/scissors_black.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-mdpi/scissors_black.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/clipboard_paste_button_black.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-xhdpi/clipboard_paste_button_black.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-xhdpi/ic_arrow_back.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_content_cut_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-xhdpi/ic_content_cut_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_content_paste_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-xhdpi/ic_content_paste_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_unfold_less.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-xhdpi/ic_unfold_less.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/scissors_black.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-xhdpi/scissors_black.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/clipboard_paste_button_black.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-xxhdpi/clipboard_paste_button_black.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-xxhdpi/ic_arrow_back.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_content_cut_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-xxhdpi/ic_content_cut_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_content_paste_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-xxhdpi/ic_content_paste_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_unfold_less.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-xxhdpi/ic_unfold_less.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/scissors_black.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-xxhdpi/scissors_black.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/clipboard_paste_button_black.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-xxxhdpi/clipboard_paste_button_black.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-xxxhdpi/ic_arrow_back.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_content_cut_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-xxxhdpi/ic_content_cut_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_content_paste_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-xxxhdpi/ic_content_paste_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_unfold_less.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-xxxhdpi/ic_unfold_less.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/scissors_black.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/drawable-xxxhdpi/scissors_black.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/rounded_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_get_permission.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
20 |
21 |
26 |
27 |
32 |
33 |
38 |
39 |
44 |
51 |
52 |
59 |
60 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_shorten.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_shorten_and_share.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/widget_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
18 |
19 |
30 |
31 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/window_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
15 |
16 |
22 |
23 |
29 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #00000000
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 10dp
6 | 50dp
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Shortlr
3 | http://cb.lk/api/v1/
4 | http://cb.lk/
5 | Not a URL!
6 | Shorten
7 | Back
8 | cb.lk
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/widget_info.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/test/java/com/codingblocks/shortlr/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.codingblocks.shortlr;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.1'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coding-blocks/shortlr_android_app/b560e64adde13bf53fc18b8b59019a291995f6b9/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Apr 15 14:00:16 IST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------