-
-
Save rafaeltoledo/6f1a0b0c9307ed7c9143bed0d091e769 to your computer and use it in GitHub Desktop.
Android 23
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
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:background="@drawable/frame"> | |
<TextView android:id="@+id/nome" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_centerVertical="true" | |
android:layout_alignParentLeft="true" | |
android:textSize="10pt" | |
android:textColor="#FFFFFF" /> | |
</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
package net.rafaeltoledo.restaurante; | |
import android.appwidget.AppWidgetProvider; | |
public class WidgetAplicativo extends AppWidgetProvider { | |
} |
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
<?xml version="1.0" encoding="utf-8"?> | |
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" | |
android:minWidth="300dip" | |
android:minHeight="79dip" | |
android:updatePeriodMillis="1800000" | |
android:initialLayout="@layout/widget" /> |
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
<receiver android:name=".WidgetAplicativo" | |
android:label="@string/app_name" | |
android:icon="@drawable/ic_launcher"> | |
<intent-filter> | |
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> | |
</intent-filter> | |
<meta-data | |
android:name="android.appwidget.provider" | |
android:resource="@xml/provedor_widget" /> | |
</receiver> |
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
@Override | |
public void onUpdate(Context context, AppWidgetManager appWidgetManager, | |
int[] appWidgetIds) { | |
ComponentName cn = new ComponentName(context, WidgetApp.class); | |
RemoteViews atualizarFrame = new RemoteViews("net.rafaeltoledo.restaurante", R.layout.widget); | |
GerenciadorRestaurantes gerenciador = new GerenciadorRestaurantes(context); | |
try { | |
Cursor c = gerenciador.getReadableDatabase().rawQuery("SELECT COUNT(*) FROM restaurantes", null); | |
c.moveToFirst(); | |
int count = c.getInt(0); | |
c.close(); | |
if (count > 0) { | |
int offset = (int) (count * Math.random()); | |
String args[] = {String.valueOf(offset)}; | |
c = gerenciador.getReadableDatabase().rawQuery("SELECT nome FROM restaurantes LIMIT 1 OFFSET ?", args); | |
c.moveToFirst(); | |
atualizarFrame.setTextViewText(R.id.nome, c.getString(0)); | |
} else { | |
atualizarFrame.setTextViewText(R.id.nome, context.getString(R.string.vazio)); | |
} | |
} finally { | |
gerenciador.close(); | |
} | |
appWidgetManager.updateAppWidget(cn, atualizarFrame); | |
} |
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
<string name="vazio">Nenhum registro.</string> |
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
<string name="vazio">Ningún registro.</string> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment