-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #169 from camarm-dev/dev
- Loading branch information
Showing
100 changed files
with
199,332 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ | |
/docs/_site/ | ||
/data/remede.db | ||
/data/remede-less.db | ||
/data/remede.*.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
app/android/app/src/main/java/com/camarm/remede/RemedeWordOfDayWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package com.camarm.remede; | ||
|
||
import android.app.PendingIntent; | ||
import android.appwidget.AppWidgetManager; | ||
import android.appwidget.AppWidgetProvider; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.os.StrictMode; | ||
import android.widget.RemoteViews; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.io.IOException; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.util.Scanner; | ||
|
||
/** | ||
* Implementation of App Widget functionality. | ||
*/ | ||
public class RemedeWordOfDayWidget extends AppWidgetProvider { | ||
|
||
public static String CLICK_ACTION = "com.camarm.remede.action.OPEN_WORD_OF_DAY"; | ||
public static String DEFAULT_WORD_JSON = "{}"; | ||
|
||
private static JSONObject getJsonResponse(URL url) throws JSONException, IOException { | ||
String plain = getPlainResponse(url); | ||
return new JSONObject(plain); | ||
} | ||
|
||
private static String getPlainResponse(URL url) throws IOException { | ||
String inline = ""; | ||
Scanner scanner = new Scanner(url.openStream()); | ||
while (scanner.hasNext()) { | ||
inline += scanner.nextLine(); | ||
} | ||
return inline; | ||
} | ||
|
||
public static JSONObject getWordDocument(String word) throws JSONException, IOException { | ||
URL getDocumentUrl = new URL("https://api-remede.camarm.fr/word/" + word); | ||
return getJsonResponse(getDocumentUrl); | ||
} | ||
|
||
public static String getWordOfDay() throws IOException, JSONException { | ||
URL getWordUrl = new URL("https://api-remede.camarm.fr/word-of-day"); | ||
|
||
HttpURLConnection wordConnection = (HttpURLConnection) getWordUrl.openConnection(); | ||
wordConnection.setRequestMethod("GET"); | ||
wordConnection.connect(); | ||
|
||
if (wordConnection.getResponseCode() == 200) { | ||
return getPlainResponse(getWordUrl); | ||
} else { | ||
throw new IOException(); | ||
} | ||
} | ||
|
||
|
||
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, | ||
int appWidgetId) { | ||
|
||
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); | ||
|
||
StrictMode.setThreadPolicy(policy); | ||
|
||
// Construct the RemoteViews object | ||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.remede_word_of_day_widget); | ||
|
||
// Get word of day | ||
String word; | ||
try { | ||
word = getWordOfDay().replaceAll("\"", ""); | ||
} catch (JSONException | IOException e) { | ||
word = "remède"; | ||
} | ||
|
||
JSONObject wordDocument; | ||
|
||
String nature; | ||
String phoneme; | ||
String definition; | ||
try { | ||
wordDocument = getWordDocument(word); | ||
nature = wordDocument.getJSONArray("definitions").getJSONObject(0).getString("classe"); | ||
phoneme = wordDocument.getString("ipa"); | ||
definition = wordDocument.getJSONArray("definitions").getJSONObject(0).getJSONObject("explications").getString("1"); | ||
definition = definition.replaceAll("<[^>]*>", ""); | ||
if (definition.length() > 100) { | ||
definition = definition.substring(0, 90) + "..."; | ||
} | ||
} catch (JSONException | IOException e) { | ||
nature = "Nom propre"; | ||
phoneme = "/ʁəmɛd/"; | ||
definition = "(Informatique) Dictionnaire français, open source et gratuit qui a pour objectif de remplacer Antidote."; | ||
} | ||
|
||
// Update text on widget | ||
String capitalizedWord = word.substring(0, 1).toUpperCase() + word.substring(1); | ||
views.setTextViewText(R.id.wodwidget_word, capitalizedWord); | ||
views.setTextViewText(R.id.wodwidget_nature, nature); | ||
views.setTextViewText(R.id.wodwidget_phoneme, phoneme); | ||
views.setTextViewText(R.id.wodwidget_definition, definition); | ||
|
||
// Handle clicks | ||
Intent intent = new Intent(context, RemedeWordOfDayWidget.class).setAction(CLICK_ACTION).setData(Uri.parse(context.getResources().getString(R.string.custom_url_scheme) + "://dictionnaire/" + word)); | ||
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); | ||
views.setOnClickPendingIntent(R.id.container, pendingIntent); | ||
|
||
// Instruct the widget manager to update the widget | ||
appWidgetManager.updateAppWidget(appWidgetId, views); | ||
} | ||
|
||
@Override | ||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { | ||
// There may be multiple widgets active, so update all of them | ||
for (int appWidgetId : appWidgetIds) { | ||
updateAppWidget(context, appWidgetManager, appWidgetId); | ||
} | ||
} | ||
|
||
@Override | ||
public void onEnabled(Context context) { | ||
// Enter relevant functionality for when the first widget is created | ||
} | ||
|
||
@Override | ||
public void onDisabled(Context context) { | ||
// Enter relevant functionality for when the last widget is disabled | ||
} | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
super.onReceive(context, intent); | ||
if (CLICK_ACTION.equals(intent.getAction())) { | ||
Intent searchbarIntent = new Intent(context, MainActivity.class) | ||
.setData(intent.getData()) | ||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); | ||
context.startActivity(searchbarIntent); | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle"> | ||
<corners | ||
android:radius="15dp" /> | ||
<solid android:color="@color/background"/> | ||
<size | ||
android:height="110dp" | ||
android:width="250dp" /> | ||
</shape> |
Binary file not shown.
Binary file not shown.
127 changes: 127 additions & 0 deletions
127
app/android/app/src/main/res/layout/remede_word_of_day_widget.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
style="@style/Widget.Android.AppWidget.Container" | ||
android:id="@+id/container" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@android:color/transparent" | ||
android:theme="@style/AppTheme.AppWidgetContainer"> | ||
|
||
<LinearLayout | ||
android:background="@drawable/rounded" | ||
style="@style/Widget.Android.AppWidget.InnerView" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_centerHorizontal="true" | ||
android:layout_centerVertical="true" | ||
android:orientation="vertical"> | ||
|
||
<LinearLayout | ||
style="@style/Widget.Android.AppWidget.InnerView" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="bottom" | ||
android:layout_margin="0dp" | ||
android:layout_marginBottom="0dp" | ||
android:background="@color/background" | ||
android:orientation="horizontal" | ||
android:padding="0dp" | ||
android:paddingStart="5dp"> | ||
|
||
<TextView | ||
style="@style/Widget.Android.AppWidget.Text" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="bottom" | ||
android:layout_marginStart="2dp" | ||
android:layout_marginBottom="0dp" | ||
android:contentDescription="@string/wodwidget_label" | ||
android:paddingBottom="0dp" | ||
android:paddingTop="3dp" | ||
android:text="@string/wodwidget_label" | ||
android:textSize="12sp" | ||
android:textStyle="bold" /> | ||
</LinearLayout> | ||
|
||
<LinearLayout | ||
style="@style/Widget.Android.AppWidget.InnerView" | ||
android:padding="0dp" | ||
android:layout_width="match_parent" | ||
android:background="@color/background" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal"> | ||
|
||
<TextView | ||
android:id="@+id/wodwidget_word" | ||
style="@style/Widget.Android.AppWidget.Text" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:contentDescription="@string/wodwidget_word" | ||
android:fontFamily="@font/ibm_plex_serif_bold" | ||
android:text="@string/wodwidget_word" | ||
android:textSize="32sp" | ||
android:textStyle="bold" /> | ||
|
||
<TextView | ||
android:id="@+id/wodwidget_nature" | ||
style="@style/Widget.Android.AppWidget.TextSecondary" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:textAlignment="viewEnd" | ||
android:layout_marginEnd="8dp" | ||
android:contentDescription="@string/wodwidget_nature" | ||
android:fontFamily="@font/ibm_plex_serif_bold" | ||
android:text="@string/wodwidget_nature" | ||
android:textSize="19sp" | ||
android:textStyle="bold" /> | ||
</LinearLayout> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="start|center_vertical" | ||
android:orientation="horizontal"> | ||
|
||
|
||
<TextView | ||
android:id="@+id/wodwidget_phoneme" | ||
style="@style/Widget.Android.AppWidget.TextSecondary" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_vertical" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginBottom="8dp" | ||
android:contentDescription="@string/wodwidget_phoneme" | ||
android:fontFamily="@font/ibm_plex_serif_bold" | ||
android:text="@string/wodwidget_phoneme" | ||
android:textSize="17sp" | ||
android:textStyle="bold" /> | ||
</LinearLayout> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="start|center_vertical" | ||
android:orientation="horizontal"> | ||
|
||
|
||
<TextView | ||
android:id="@+id/wodwidget_definition" | ||
style="@style/Widget.Android.AppWidget.TextTertiary" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_vertical" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginBottom="8dp" | ||
android:contentDescription="@string/wodwidget_desc" | ||
android:fontFamily="@font/ibm_plex_serif_bold" | ||
android:text="@string/wodwidget_desc" | ||
android:textSize="15sp" | ||
android:textStyle="bold" /> | ||
</LinearLayout> | ||
|
||
|
||
</LinearLayout> | ||
|
||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<resources> | ||
<color name="light_blue_50">#FFE1F5FE</color> | ||
<color name="light_blue_200">#FF81D4FA</color> | ||
<color name="light_blue_600">#FF039BE5</color> | ||
<color name="light_blue_900">#FF01579B</color> | ||
<color name="background">#000000</color> | ||
<color name="text">#FFF</color> | ||
<color name="textSecondary">#B9B9B9</color> | ||
<color name="textGrey">#7F7F7F</color> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.