forked from NordicSemiconductor/nRF-Logger-API
-
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.
- Loading branch information
Showing
44 changed files
with
1,212 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea/ | ||
local.properties | ||
build/ |
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,29 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 29 | ||
buildToolsVersion "29.0.3" | ||
|
||
defaultConfig { | ||
applicationId "no.nordicsemi.android.log.example" | ||
minSdkVersion 17 | ||
targetSdkVersion 29 | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' | ||
} | ||
} | ||
compileOptions { | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation 'com.google.android.material:material:1.2.0-beta01' | ||
implementation 'androidx.fragment:fragment:1.3.0-alpha05' | ||
implementation 'no.nordicsemi.android:log:2.2.0' | ||
} |
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,32 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="no.nordicsemi.android.log.example" > | ||
|
||
<uses-permission android:name="no.nordicsemi.android.LOG" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme" | ||
tools:ignore="AllowBackup"> | ||
<activity | ||
android:name="no.nordicsemi.android.log.example.MainActivity" | ||
android:label="@string/app_name" | ||
android:windowSoftInputMode="adjustPan" > | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
<provider | ||
android:name="no.nordicsemi.android.log.example.localprovider.MyLogContentProvider" | ||
android:authorities="no.nordicsemi.android.log.example" | ||
android:exported="false" /> | ||
</application> | ||
|
||
</manifest> |
67 changes: 67 additions & 0 deletions
67
samples/example2/app/src/main/java/no/nordicsemi/android/log/example/LogAdapter.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,67 @@ | ||
package no.nordicsemi.android.log.example; | ||
|
||
import java.util.Calendar; | ||
|
||
import no.nordicsemi.android.log.LogContract.Log.Level; | ||
import android.content.Context; | ||
import android.database.Cursor; | ||
import android.graphics.Color; | ||
import android.util.SparseIntArray; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.CursorAdapter; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
public class LogAdapter extends CursorAdapter { | ||
private static final SparseIntArray mColors = new SparseIntArray(); | ||
|
||
static { | ||
mColors.put(Level.DEBUG, 0xFF009CDE); | ||
mColors.put(Level.VERBOSE, 0xFFB8B056); | ||
mColors.put(Level.INFO, Color.BLACK); | ||
mColors.put(Level.APPLICATION, 0xFF238C0F); | ||
mColors.put(Level.WARNING, 0xFFD77926); | ||
mColors.put(Level.ERROR, Color.RED); | ||
} | ||
|
||
public LogAdapter(@NonNull final Context context) { | ||
super(context, null, 0); | ||
} | ||
|
||
@Override | ||
public View newView(final Context context, final Cursor cursor, final ViewGroup parent) { | ||
final View view = LayoutInflater.from(context).inflate(R.layout.log_item, parent, false); | ||
|
||
final ViewHolder holder = new ViewHolder(); | ||
holder.time = view.findViewById(R.id.time); | ||
holder.data = view.findViewById(R.id.data); | ||
view.setTag(holder); | ||
return view; | ||
} | ||
|
||
@Override | ||
public void bindView(final View view, final Context context, final Cursor cursor) { | ||
final ViewHolder holder = (ViewHolder) view.getTag(); | ||
final Calendar calendar = Calendar.getInstance(); | ||
calendar.setTimeInMillis(cursor.getLong(1 /* TIME */)); | ||
holder.time.setText(context.getString(R.string.log, calendar)); | ||
|
||
final int level = cursor.getInt(2 /* LEVEL */); | ||
holder.data.setText(cursor.getString(3 /* DATA */)); | ||
holder.data.setTextColor(mColors.get(level)); | ||
} | ||
|
||
@Override | ||
public boolean isEnabled(final int position) { | ||
return false; | ||
} | ||
|
||
private static class ViewHolder { | ||
private TextView time; | ||
private TextView data; | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
samples/example2/app/src/main/java/no/nordicsemi/android/log/example/MainActivity.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,45 @@ | ||
package no.nordicsemi.android.log.example; | ||
|
||
import android.content.ContentProviderClient; | ||
import android.os.Bundle; | ||
import android.widget.Toast; | ||
|
||
import androidx.annotation.Nullable; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import no.nordicsemi.android.log.LogContract; | ||
import no.nordicsemi.android.log.example.fragment.MainFragment; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(@Nullable final Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
// Show information if nRF Logger is not installed | ||
if (!logProviderExists()) { | ||
Toast.makeText(this, R.string.error_no_nrf_logger, Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
// Show the main fragment | ||
if (savedInstanceState == null) { | ||
getSupportFragmentManager() | ||
.beginTransaction() | ||
.add(R.id.container, new MainFragment()) | ||
.commit(); | ||
} | ||
} | ||
|
||
private boolean logProviderExists() { | ||
// The method below requires API 16 | ||
final ContentProviderClient unstableClient = getContentResolver() | ||
.acquireUnstableContentProviderClient(LogContract.AUTHORITY); | ||
if (unstableClient == null) | ||
return false; | ||
|
||
unstableClient.release(); | ||
return true; | ||
} | ||
|
||
} |
83 changes: 83 additions & 0 deletions
83
...2/app/src/main/java/no/nordicsemi/android/log/example/fragment/KeyNameDialogFragment.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,83 @@ | ||
package no.nordicsemi.android.log.example.fragment; | ||
|
||
import no.nordicsemi.android.log.example.R; | ||
import android.app.Dialog; | ||
import android.content.DialogInterface; | ||
import android.os.Bundle; | ||
import android.text.TextUtils; | ||
import android.view.KeyEvent; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.inputmethod.EditorInfo; | ||
import android.widget.EditText; | ||
import android.widget.TextView; | ||
import android.widget.TextView.OnEditorActionListener; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.appcompat.app.AlertDialog; | ||
import androidx.fragment.app.DialogFragment; | ||
|
||
public class KeyNameDialogFragment extends DialogFragment implements | ||
OnEditorActionListener, DialogInterface.OnClickListener { | ||
public static final String RESULT = "session"; | ||
public static final String RESULT_KEY = "session_key"; | ||
public static final String RESULT_NAME = "session_name"; | ||
|
||
private EditText mKeyView; | ||
private EditText mNameView; | ||
|
||
@NonNull | ||
@Override | ||
public Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) { | ||
final AlertDialog.Builder builder = new AlertDialog.Builder(requireContext()) | ||
.setTitle(R.string.dialog_title) | ||
.setNegativeButton(android.R.string.no, null) | ||
.setPositiveButton(android.R.string.ok, this); | ||
|
||
final View view = LayoutInflater.from(requireContext()) | ||
.inflate(R.layout.fragment_dialog_key_name, null); | ||
mKeyView = view.findViewById(R.id.key); | ||
mNameView = view.findViewById(R.id.name); | ||
builder.setView(view); | ||
return builder.create(); | ||
} | ||
|
||
/** | ||
* Called when OK button has been pressed. | ||
*/ | ||
@Override | ||
public void onClick(final DialogInterface dialog, final int which) { | ||
// Validate key and name | ||
String key = mKeyView.getText().toString().trim(); | ||
String name = mNameView.getText().toString().trim(); | ||
boolean valid = true; | ||
|
||
if (TextUtils.isEmpty(key)) { | ||
valid = false; | ||
mKeyView.setError(getString(R.string.dialog_error)); | ||
} | ||
|
||
if (TextUtils.isEmpty(name)) { | ||
valid = false; | ||
mNameView.setError(getString(R.string.dialog_error)); | ||
} | ||
|
||
if (valid) { | ||
final Bundle result = new Bundle(); | ||
result.putString(KeyNameDialogFragment.RESULT_KEY, key); | ||
result.putString(KeyNameDialogFragment.RESULT_NAME, name); | ||
getParentFragmentManager().setFragmentResult(KeyNameDialogFragment.RESULT, result); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) { | ||
if (EditorInfo.IME_ACTION_DONE == actionId) { | ||
// Return input text to activity | ||
onClick(null, DialogInterface.BUTTON_POSITIVE); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
Oops, something went wrong.