Skip to content

Commit 49b5908

Browse files
committed
initial commit.
0 parents  commit 49b5908

File tree

59 files changed

+3847
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+3847
-0
lines changed

Library/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

Library/build.gradle

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 28
5+
6+
defaultConfig {
7+
minSdkVersion 19
8+
targetSdkVersion 28
9+
versionCode 1
10+
versionName "1.0"
11+
12+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13+
14+
}
15+
16+
buildTypes {
17+
release {
18+
minifyEnabled false
19+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20+
}
21+
}
22+
23+
}
24+
25+
dependencies {
26+
implementation fileTree(dir: 'libs', include: ['*.jar'])
27+
testImplementation 'junit:junit:4.12'
28+
androidTestImplementation 'androidx.test:runner:1.1.1'
29+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
30+
implementation 'androidx.appcompat:appcompat:1.0.2'
31+
implementation 'androidx.browser:browser:1.0.0'
32+
}

Library/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.next.androidintentlibrary;
2+
3+
import android.content.Context;
4+
import androidx.test.InstrumentationRegistry;
5+
import androidx.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+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest
19+
{
20+
@Test
21+
public void useAppContext() throws Exception
22+
{
23+
// Context of the app under test.
24+
Context appContext = InstrumentationRegistry.getTargetContext();
25+
26+
assertEquals("com.next.androidintentlibrary.test", appContext.getPackageName());
27+
}
28+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.next.androidintentlibrary"/>
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
package com.next.androidintentlibrary;
2+
3+
import android.app.Activity;
4+
import android.content.ActivityNotFoundException;
5+
import android.content.Context;
6+
import android.content.Intent;
7+
import android.os.Build;
8+
import android.provider.AlarmClock;
9+
import androidx.annotation.NonNull;
10+
import androidx.annotation.RequiresApi;
11+
12+
public class AlarmIntents
13+
{
14+
//TODO: add to readme
15+
// Resources
16+
// https://Stackoverflow.com android intent documentation (no longer available)
17+
// https://github.com/d-tarasov/android-intents
18+
// https://developer.android.com/guide/components/intents-common.html
19+
// https://github.com/marvinlabs/android-intents
20+
// NOTE: Flags
21+
// NO 1: FLAG_ACTIVITY_NEW_TASK:
22+
// When using this flag, if a task is already running for the activity you are now starting,
23+
// then a new activity will not be started; instead,
24+
// the current task will simply be brought to the front of the screen with the state it was last in.
25+
26+
// NOTE: common actions
27+
// NO 2: ACTION_MAIN
28+
// Activity Action Start as a main entry point, does not expect to receive data.
29+
// NO 3: ACTION_VIEW
30+
// This is the most common action performed on a data, usually to view sth.
31+
// NO 4: ACTION_EDIT
32+
// This is the most common action to edit a data, usually to edit some part of intent.
33+
// NO 5: ACTION_DEFAULT
34+
// search on it
35+
36+
// NOTE: you need to use constant value of an action for intent filter
37+
// NOTE: you can find constant value for each action in docs (Ctrl + Q)
38+
// NOTE: Intent Filter Example
39+
// <activity ...>
40+
// <intent-filter>
41+
// <action android:name="android.intent.action.INSERT" />
42+
// <data android:mimeType="vnd.android.cursor.dir/event" />
43+
// <category android:name="android.intent.category.DEFAULT" />
44+
// </intent-filter>
45+
// </activity>
46+
private Context context;
47+
Intent intent;
48+
49+
AlarmIntents(Context context)
50+
{
51+
this.context = context;
52+
}
53+
54+
public AlarmIntents from(@NonNull Context context)
55+
{
56+
return new AlarmIntents(context);
57+
}
58+
59+
// NOTE: requires com.android.alarm.permission.SET_ALARM permission
60+
public AlarmIntents createAlarmIntent(String message, int hour, int minutes, boolean skipUi)
61+
{
62+
// create alarm
63+
intent = new Intent(AlarmClock.ACTION_SET_ALARM);
64+
intent.putExtra(AlarmClock.EXTRA_MESSAGE, message);
65+
intent.putExtra(AlarmClock.EXTRA_HOUR, hour);
66+
intent.putExtra(AlarmClock.EXTRA_MINUTES, minutes);
67+
intent.putExtra(AlarmClock.EXTRA_SKIP_UI, skipUi);
68+
return this;
69+
}
70+
71+
// NOTE: requires com.android.alarm.permission.SET_ALARM permission
72+
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
73+
public AlarmIntents createAlarmIntent(String message, int hour, int minutes, boolean vibrate, boolean skipUi)
74+
{
75+
// create alarm
76+
intent = new Intent(AlarmClock.ACTION_SET_ALARM);
77+
intent.putExtra(AlarmClock.EXTRA_MESSAGE, message);
78+
intent.putExtra(AlarmClock.EXTRA_HOUR, hour);
79+
intent.putExtra(AlarmClock.EXTRA_MINUTES, minutes);
80+
81+
intent.putExtra(AlarmClock.EXTRA_VIBRATE, vibrate);
82+
// TODO: intent.putExtra(AlarmClock.EXTRA_DAYS, days);
83+
// TODO: intent.putExtra(AlarmClock.EXTRA_RINGTONE, ringtone);
84+
85+
intent.putExtra(AlarmClock.EXTRA_SKIP_UI, skipUi);
86+
return this;
87+
}
88+
89+
// NOTE: requires com.android.alarm.permission.SET_ALARM permission
90+
@RequiresApi(api = Build.VERSION_CODES.M)
91+
public AlarmIntents createAlarmIntent(String message, int hour, int minutes, boolean vibrate, boolean isPm, boolean skipUi)
92+
{
93+
// create alarm
94+
intent = new Intent(AlarmClock.ACTION_SET_ALARM);
95+
intent.putExtra(AlarmClock.EXTRA_MESSAGE, message);
96+
intent.putExtra(AlarmClock.EXTRA_HOUR, hour);
97+
intent.putExtra(AlarmClock.EXTRA_MINUTES, minutes);
98+
99+
intent.putExtra(AlarmClock.EXTRA_VIBRATE, vibrate);
100+
// TODO: intent.putExtra(AlarmClock.EXTRA_DAYS, days);
101+
// TODO: intent.putExtra(AlarmClock.EXTRA_RINGTONE, ringtone);
102+
intent.putExtra(AlarmClock.EXTRA_IS_PM, isPm);
103+
intent.putExtra(AlarmClock.EXTRA_SKIP_UI, skipUi);
104+
return this;
105+
}
106+
107+
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
108+
public AlarmIntents showAlarmsIntent()
109+
{
110+
Intent intent = new Intent(AlarmClock.ACTION_SHOW_ALARMS);
111+
return this;
112+
}
113+
114+
public Intent build()
115+
{
116+
return intent;
117+
}
118+
119+
private void startActivity(Intent intent)
120+
{
121+
if (!(context instanceof Activity))
122+
{
123+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
124+
}
125+
context.startActivity(intent);
126+
}
127+
128+
public boolean show()
129+
{
130+
Intent alarmIntent = build();
131+
try
132+
{
133+
startActivity(alarmIntent);
134+
} catch (ActivityNotFoundException e)
135+
{
136+
return false;
137+
}
138+
return true;
139+
}
140+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package com.next.androidintentlibrary;
2+
3+
import android.app.Activity;
4+
import android.content.ActivityNotFoundException;
5+
import android.content.Context;
6+
import android.content.Intent;
7+
import android.net.Uri;
8+
import androidx.annotation.NonNull;
9+
import android.text.TextUtils;
10+
11+
import java.net.URL;
12+
13+
public class BrowserIntents
14+
{
15+
private Context context;
16+
protected Intent intent;
17+
18+
BrowserIntents(Context context)
19+
{
20+
this.context = context;
21+
}
22+
23+
public BrowserIntents from(@NonNull Context context)
24+
{
25+
return new BrowserIntents(context);
26+
}
27+
28+
public BrowserIntents openBrowserIntent()
29+
{
30+
intent = new Intent();
31+
intent.setAction(Intent.ACTION_MAIN);
32+
intent.addCategory(Intent.CATEGORY_APP_BROWSER);
33+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
34+
return this;
35+
}
36+
37+
public BrowserIntents openLink(String url)
38+
{
39+
// if protocol isn't defined use http by default
40+
if (!TextUtils.isEmpty(url) && !url.contains("://"))
41+
{
42+
url = "http://" + url;
43+
}
44+
45+
intent = new Intent();
46+
intent.setAction(Intent.ACTION_VIEW);
47+
intent.setData(Uri.parse(url));
48+
return this;
49+
}
50+
51+
public BrowserIntents openLink(URL url)
52+
{
53+
return openLink(url.toString());
54+
}
55+
56+
// TODO: 8/30/2017 How to use URL Http And Https ?
57+
public BrowserIntents LoadWebURL(String http)
58+
{
59+
Uri webpage = Uri.parse(http);
60+
intent = new Intent(Intent.ACTION_VIEW);
61+
intent.setData(webpage);// TODO: 8/30/2017 This URL can be Http Or Https
62+
intent.setType("text/plain");
63+
intent.setType("text/html");
64+
intent.setType("application/xhtml+xml");
65+
intent.setType("application/vnd.wap.xhtml+xml");
66+
return this;
67+
}
68+
69+
public BrowserIntents openAUrlInBrowser()
70+
{
71+
Uri uri = Uri.parse("https://google.com");
72+
intent = new Intent(Intent.ACTION_VIEW, uri);
73+
return this;
74+
}
75+
76+
public Intent build()
77+
{
78+
return intent;
79+
}
80+
81+
private void startActivity(Intent intent)
82+
{
83+
if (!(context instanceof Activity))
84+
{
85+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
86+
}
87+
context.startActivity(intent);
88+
}
89+
90+
public boolean show()
91+
{
92+
Intent browserIntent = build();
93+
try
94+
{
95+
startActivity(browserIntent);
96+
} catch (ActivityNotFoundException e)
97+
{
98+
return false;
99+
}
100+
return true;
101+
}
102+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.next.androidintentlibrary;
2+
3+
import android.app.Activity;
4+
import android.content.ActivityNotFoundException;
5+
import android.content.Context;
6+
import android.content.Intent;
7+
import androidx.annotation.NonNull;
8+
9+
public class CalculatorIntents
10+
{
11+
private Context context;
12+
private Intent intent;
13+
14+
CalculatorIntents(Context context)
15+
{
16+
this.context = context;
17+
}
18+
19+
public CalculatorIntents from(@NonNull Context context)
20+
{
21+
return new CalculatorIntents(context);
22+
}
23+
24+
public CalculatorIntents openCalculatorIntent()
25+
{
26+
intent = new Intent();
27+
intent.setAction(Intent.ACTION_MAIN);
28+
intent.addCategory(Intent.CATEGORY_APP_CALCULATOR);
29+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
30+
return this;
31+
}
32+
33+
public Intent build()
34+
{
35+
return intent;
36+
}
37+
38+
private void startActivity(Intent intent)
39+
{
40+
if (!(context instanceof Activity))
41+
{
42+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
43+
}
44+
context.startActivity(intent);
45+
}
46+
47+
public boolean show()
48+
{
49+
Intent calculatorIntent = build();
50+
try
51+
{
52+
startActivity(calculatorIntent);
53+
} catch (ActivityNotFoundException e)
54+
{
55+
return false;
56+
}
57+
return true;
58+
}
59+
}

0 commit comments

Comments
 (0)