root/java/org/gnu/emacs/EmacsPreferencesActivity.java

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. startEmacsQ
  2. startEmacsDebugInit
  3. eraseDumpFile
  4. onCreate

     1 /* Communication module for Android terminals.  -*- c-file-style: "GNU" -*-
     2 
     3 Copyright (C) 2023 Free Software Foundation, Inc.
     4 
     5 This file is part of GNU Emacs.
     6 
     7 GNU Emacs is free software: you can redistribute it and/or modify
     8 it under the terms of the GNU General Public License as published by
     9 the Free Software Foundation, either version 3 of the License, or (at
    10 your option) any later version.
    11 
    12 GNU Emacs is distributed in the hope that it will be useful,
    13 but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 GNU General Public License for more details.
    16 
    17 You should have received a copy of the GNU General Public License
    18 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
    19 
    20 package org.gnu.emacs;
    21 
    22 import java.io.File;
    23 
    24 import android.app.Activity;
    25 
    26 import android.content.Intent;
    27 
    28 import android.os.Bundle;
    29 import android.os.Build;
    30 
    31 import android.widget.Toast;
    32 
    33 import android.preference.*;
    34 
    35 /* This module provides a ``preferences'' display for Emacs.  It is
    36    supposed to be launched from inside the Settings application to
    37    perform various actions, such as starting Emacs with the ``-Q''
    38    option, which would not be possible otherwise, as there is no
    39    command line on Android.
    40 
    41    Android provides a preferences activity, but it is deprecated.
    42    Unfortunately, there is no alternative that looks the same way.  */
    43 
    44 @SuppressWarnings ("deprecation")
    45 public class EmacsPreferencesActivity extends PreferenceActivity
    46 {
    47   /* Restart Emacs with -Q.  Call EmacsThread.exit to kill Emacs now,
    48      and tell the system to start EmacsActivity with some parameters
    49      later.  */
    50 
    51   private void
    52   startEmacsQ ()
    53   {
    54     Intent intent;
    55 
    56     intent = new Intent (this, EmacsActivity.class);
    57     intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK
    58                      | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    59     intent.putExtra ("org.gnu.emacs.STARTUP_ARGUMENT", "--quick");
    60     startActivity (intent);
    61     System.exit (0);
    62   }
    63 
    64   /* Restart Emacs with `--debug-init'.  Call EmacsThread.exit to kill
    65      Emacs now, and tell the system to EmacsActivity with some
    66      parameters later.  */
    67 
    68   private void
    69   startEmacsDebugInit ()
    70   {
    71     Intent intent;
    72 
    73     intent = new Intent (this, EmacsActivity.class);
    74     intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK
    75                      | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    76     intent.putExtra ("org.gnu.emacs.STARTUP_ARGUMENT", "--debug-init");
    77     startActivity (intent);
    78     System.exit (0);
    79   }
    80 
    81   /* Erase Emacs's dump file.  */
    82 
    83   private void
    84   eraseDumpFile ()
    85   {
    86     String wantedDumpFile;
    87     File file;
    88     Toast toast;
    89 
    90     wantedDumpFile = ("emacs-" + EmacsNative.getFingerprint ()
    91                       + ".pdmp");
    92     file = new File (getFilesDir (), wantedDumpFile);
    93 
    94     if (file.exists ())
    95       file.delete ();
    96 
    97     /* Make sure to clear EmacsApplication.dumpFileName, or
    98        starting Emacs without restarting this program will
    99        make Emacs try to load a nonexistent dump file.  */
   100     EmacsApplication.dumpFileName = null;
   101 
   102     /* Display a message stating that the dump file has been
   103        erased.  */
   104     toast = Toast.makeText (this, "Dump file removed",
   105                             Toast.LENGTH_SHORT);
   106     toast.show ();
   107   }
   108 
   109   @Override
   110   public final void
   111   onCreate (Bundle savedInstanceState)
   112   {
   113     Preference tem;
   114     Preference.OnPreferenceClickListener listener;
   115 
   116     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
   117       setTheme (android.R.style.Theme_DeviceDefault_Settings);
   118     else if (Build.VERSION.SDK_INT
   119              >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
   120       setTheme (android.R.style.Theme_DeviceDefault);
   121 
   122     /* This must come before using any preference APIs.  */
   123     super.onCreate (savedInstanceState);
   124 
   125     /* Add preferences from the XML file where they are defined.  */
   126     addPreferencesFromResource (R.xml.preferences);
   127 
   128     /* Now, set up on click handlers for each of the preferences
   129        items.  */
   130 
   131     tem = findPreference ("start_quick");
   132     listener = new Preference.OnPreferenceClickListener () {
   133         @Override
   134         public boolean
   135         onPreferenceClick (Preference preference)
   136         {
   137           startEmacsQ ();
   138           return true;
   139         }
   140       };
   141 
   142     tem.setOnPreferenceClickListener (listener);
   143     tem = findPreference ("start_debug_init");
   144     listener = new Preference.OnPreferenceClickListener () {
   145         @Override
   146         public boolean
   147         onPreferenceClick (Preference preference)
   148         {
   149           startEmacsDebugInit ();
   150           return true;
   151         }
   152       };
   153 
   154     tem.setOnPreferenceClickListener (listener);
   155     tem = findPreference ("erase_dump");
   156     listener = new Preference.OnPreferenceClickListener () {
   157         @Override
   158         public boolean
   159         onPreferenceClick (Preference preference)
   160         {
   161           eraseDumpFile ();
   162           return true;
   163         }
   164       };
   165 
   166     tem.setOnPreferenceClickListener (listener);
   167   }
   168 };

/* [<][>][^][v][top][bottom][index][help] */